Menu
  • HOME
  • TAGS

Custom changes to entity generated classes

c#,vb.net,entity-framework-6,poco,t4

You could take a code-first approach (EDIT: @Steve Greene's helpful link) and write the classes yourself. If you want to keep the auto-generation, you will have to edit the .tt file itself. Editing the file is not fun, especially with no intellisense, and trying to figure out what someone...

C# - Entity Framework - Large seed data code-first

c#,entity-framework,ef-code-first,code-first,poco

Reference System.Data in your database project and add the NuGet package EntityFramework.BulkInsert. Insert your data in the seed method if you detect that it's not there yet: protected override void Seed(BulkEntities context) { if (!context.BulkItems.Any()) { var items = Enumerable.Range(0, 100000) .Select(s => new BulkItem { Name = s.ToString(),...

C# - EF 6 Abstract Navigation Property

c#,entity-framework,ef-code-first,abstract-class,poco

Entity Framework does not support Generic Entities, but it does support Entities that are inheriting generic classes Try to change your abstract NotaFiscal class to have a generic parameter to represent each NotaFiscalItem: public abstract class NotaFiscal<T> where T : NotaFiscalItem { public abstract ICollection<T> NotaFiscalItems { get; set; }...

C# - EF Code First Layers Definition and Logic

c#,entity-framework,poco,layer

Entities layer gotta see the DAL layer to access the objects from the DB This is where you should break your dependency. The entities should be storage-agnostic. The current popular method of bridging the entities and EF is a Repository layer that encapsulates the CRUD (Create, Read, Update, Delete)...

Entity Framework Error Deleting Entity with Foreign Key Relationship

entity-framework,entity-framework-6,poco

Since you already have the question ids to delete, something like this should work: // assuming db is your DbContext var questions = db.QuizWithQuestions .Where(q => deletedQuestions.Contains(q.Id)) .Include(q => q.QuizUserAnswers); // assuming this is your DbSet db.QuizWithQuestions.RemoveRange(questions); db.SaveChanges(); If the QuizUserAnswer entities are loaded into the context (which is what...

Extension Methods vs Instance Methods vs Static Class [closed]

c#,extension-methods,poco,static-classes,instance-methods

You asked, "If you could accomplish the desired outcome by simply placing a method in a class definition, why would a POCO combined with either a static helper class or an extension method be preferable?" The answer is that it depends on the situation, and if the methods in question...

How to add an XmlDocument to a POCO class?

c#,poco,entity-framework-6

It might be possible to Serialize the XmlDoc as a Blob but why bother? It's essentially text. public string ContentText { get; set; } private _xmlDocuent; [NotMapped] public XmlDocument Content { get { return _xmlDocumet ?? (_xmlDocument = new XmlDocuent.Parse(ContentTExt)); } } ...

What is the cause of this EF6 behaviour Find() does not return a proxy but Single() does return a proxy

c#,entity-framework,entity,poco,proxy-classes

This could happen if your context is already tracking a non-proxy BankAccount with that key by the moment you query it. The strange thing is that, although First and Single always query the database, they should return the same entity as Find does. For example, if you have a unit...

Save Object with Entity doesn't work

c#,entity-framework-5,poco

SaveChanges() needs to be called in Add()... public void Add(T entity) { Context.CreateObjectSet<T>().AddObject(entity); Context.SaveChanges(); } Or this.Commit() should be called after this.Add(category)....

Meaning of POCO classes in MVVM and Entity Framework

wpf,entity-framework,mvvm,data-binding,poco

You use the "POCO version" to build the context model for your database. If you will, POCO is just defined as Plain Old CLR Object. Just a normal class, no attributes describing infrastructure concerns or other responsibilities that your domain objects shouldn't have. so technically, your Category is also considered...

HTTPS client and server together using C++ and POCO libraries (SSL context issues)?

c++,ssl,openssl,poco,poco-libraries

To answer my own question later, I was able to edit the POCO code to allow me to specifiy a "Both" context. That is I updated the code I initially posted to be like: void Context::createSSLContext() { if (SSLManager::isFIPSEnabled()) { _pSSLContext = SSL_CTX_new(TLSv1_method()); } else { switch (_usage) { case...

MVC5 Scaffolding Dropdowns Out the Box

asp.net-mvc,asp.net-mvc-5,poco,html.dropdownlistfor,asp.net-mvc-scaffolding

Size and color are lazy loaded by default (virtual) so you need to eagerly load them: var products = context.Products.Include(p => p.Color).Include(p => p.Size).ToList(); https://msdn.microsoft.com/en-us/data/jj574232.aspx If your issue is with the drop downs, you will want to compose a viewmodel in your controller that has the list items, send that...

Solely mapping existing db to existing POCOs without designer or CodeFirst in Entity Framework 6

c#,entity-framework,ef-code-first,poco,entity-framework-6

The remark about closing this work item at CodePlex claims that since EF 6 defining different key column names of parent and child entities in a TPT mapping works with Code-First. If that is true the following Code-First mapping should allow to map your model and database: modelBuilder.Entity<Record>() .ToTable("YourRecordTableName"); modelBuilder.Entity<Record>()...

How to include POCO Library exactly?

c++,poco

To use these classes from POCO, you'll need to include the header files containing their declaration, and specify the actual namespace where they are declared #include <Poco/Net/MailMessage.h> #include <Poco/Net/SMTPClientSession.h> // .... Poco::Net::MailMessage msg; msg.addRecipient (MailRecipient (MailRecipient::PRIMARY_RECIPIENT, "[email protected]", "Bob")); msg.setSender ("Me <[email protected]>"); msg.setSubject ("Subject"); msg.setContent ("Content"); Poco::Net::SMTPClientSession smtp ("mail.example.com"); smtp.login ();...

EF 6.x Code First: Different SQL Generated for Navigation Property - What am I doing wrong?

entity-framework,ef-code-first,linq-to-entities,poco

This is standard EF behaviour. When accessing collection properties ALL related entities are lazy-loaded from the database into the collection before the results are filtered for the query. In this case actual filtering is performed by LINQ-to-Objects and not LINQ-to-Entities as you are expecting. I've found this to be a...

Mapping only some of the attributes of POCO class to database table [duplicate]

c#,entity-framework,poco

You should use NotMapped attribute: public class Entity { public int Id {get; set;} [NotMapped] public string NotMapped {get;set;} } ...

Multiple Http Servers with Poco and Boost C++

c++,boost-asio,poco,poco-libraries

HttpServerApplication is not designed to be used in this way. It's designed to be a singleton. http://pocoproject.org/docs/Poco.Util.ServerApplication.html You can fix that part by not deriving from ServerApplication in your HttpServer class. After all, you want multiple servers, not applications. In my simplest test, the following works: #include <Poco/Net/HTMLForm.h> #include <Poco/Net/HTTPRequestHandler.h>...

EF Reverse POCO Generator: Failed to load provider EntityClient

c#,visual-studio-2012,sql-server-ce,poco,entity-framework-6

Found the answer, the problem was in the ConnectionString should be as follows: <connectionStrings> <add name="Entities" connectionString="Data Source=C:\StoreContainer.sdf" providerName="Microsoft.SqlServerCe.Client.4.0" /> </connectionStrings> ...

Datasets and ASP.Net sites

c#,asp.net,.net,dataset,poco

Most people over the last decade have used an ORM such as EntityFramework or NHibernate to bypass the need to write relatively low-level code with ADO.NET's DataSet and DataTable. It also does not convey business intent (although you could argue this is not important at this level of the application)....

Trying to use methods on values within get and set accessors gives a .Net framework error

c#,entity-framework,poco

The reason that it's failing right now is because you're running into an infinite amount of calling the get part of UserName since you're trying to grab the value by trying to grab the value and decrypting it. This will cause an overflow error eventually. Your solution to this is...

Generate POCO from dynamic in C#

c#,dynamic,reflection,code-generation,poco

You can use compileassemblyfromsource to compile your string, http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.compileassemblyfromsource(v=vs.110).aspx var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } }); var cp = new CompilerParameters() { GenerateExecutable = false, GenerateInMemory = true }; cp.ReferencedAssemblies.Add("mscorlib.dll"); cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Core.dll"); // The string can...

Getting records of specific type

c#,types,visual-studio-2013,poco,entity-framework-6

As inheritance is involved, there is probably a type descriminator against the entities you have stored you can filter against and it appears as you have just one table that you have an arrangement called Table Per Hierachy (TPH) Check this link out: http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-code-first-ctp5-part-1-table-per-hierarchy-tph.aspx It refers to an OfType<T>() method...

What is equivalent display Annotation in fluent Api?

c#,entity-framework,poco

The DisplayAttribute is not used by Entity Framework, hence there's no equivalent.

asp.net web api controllers accept POCO or generic data

orm,asp.net-web-api,poco,restful-architecture,asp.net-apicontroller

Please see answers below: 1.**Using **"IDictionary of name/value pairs" is fine if your resource supports GET methods only. If you want users to post or update data, how will you validate the data? In addition, if you want to add HATEOAS, how would you do that? In terms of extension,...

Entity Framework code first: How to ignore classes

c#,entity-framework,poco,dbcontext

There are three things to ensure: Make sure you do not expose a DbSet<HairCutStyle> in your DbContext-derived class Make sure you do not have any mention of HairCutStyle in your OnModelCreating override Mark your HairCutStyle property using the NotMapped attribute. ...

Detecting when POCO entities are being initialized in Entity Framework

c#,entity-framework,entity-framework-6,poco

Why don't you simply Declare the property setter as protected; and Expose your // DO STUFF behavior as a proper method SetFirstName(string firstName)? Something like this: public class Person { public string FirstName { get; protected set; } public string SetFirstName(string value) { _firstName = value; // DO STUFF; }...

Entity Framework - Loading nested entities

linq,entity-framework,poco,dbcontext

Sadly, I had to settle with manually building the relationship of objects in code. I'm sure there's a way to make this less painful, hopefully someone can come along and give the pill for this. var personItemDict = new Dictionary<string, Item>(); var persons = context.Persons.Where(<condition>).ToDictionary(k=>k.Id, v=>v); var orders = context.Orders.Where(<condition>).ToDictionary(k=>k.OrderId,...

Serialize poco containing object property into Json

c#,xml,serialization,json.net,poco

You would have to create your own custom serialization behaviour. Have a look at this answer here : http://stackoverflow.com/a/22722467/2039359 on how to implement your own JsonConverter for Json.Net In your case you could do something like this to create your json public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)...

osx - Linking error, when building POCO library

c++,c,osx,poco,clang++

Well, my solution is to put -stdlib flag to build/config/Darwin-clang and configure build with required Darwin-clang config.

EF 5 Code First Mapping Issue

c#,entity-framework,poco

You need to use unique class names even if the model classes are in different namespaces. There's an explanation here: EF Code first, how to register same table name with different schema?...

Encrypt in C# using OpenSSL compatible format, decrypt in Poco

c#,c++,cryptography,openssl,poco

There were two issues. First, I made a mistake. I need to pass to decrypt method ONLY the bytes without the header: so I added: toDecrypt = toDectrypt.substr(16); to the code, otherwise the decryption doesn't work because the header. Secondly, I used the ENC_BASE64, so I need to encode the...

Thrift TThreadPoolServer returns “Segmentation fault; core dumped;” when handle concurrent MySQL database requests

mysql,poco,thrift

Thanks to @JensG, I found out that the problem here is because I used a global variable mySQLsession to handle all the MySQL database requests, which causes threads conflict. Thanks you all again !

Performance Issues with Include in Entity Framework

json,entity-framework,repository-pattern,asp.net-web-api2,poco

The performance has been improved by Enabling Lazy Loading.

Queries on Repository Layer in MVC application

asp.net-mvc,repository-pattern,poco

Usually, the Repository is the method of accessing the data and is therefore just an implementation technique of the DAL. I'd combine them both as the DAL. In terms of other models, I assume you mean the classes that correspond with your data items. These should also live in...

How to access get variable in POCO

c++,boost,poco

Both HTTPRequest and HTTPResponse derive from HTTPMessage, which has methods like get, has and hasToken. Also, see the comment by naab and/or try constructing HTMLForm from the request stream: HTMLForm( const HTTPRequest & request, std::istream & requestBody ); ...

MVC5 - Proper way to get multiple lists into a view (i.e. Customer Contacts, Customer Locations)

c#,entity-framework,asp.net-mvc-5,automapper,poco

Suppose You have Customer Object Like below: public string Name{ get; set; } public string CustLevel{ get; set; } public List<CustomerContact> Contacts { get; set; } public List<CustomerLocation> Locations { get; set; } Then in Razor use this model: @Html.LabelFor(t=>t.Name); @Html.LabelFor(t=>t.CustLevel); @foreach(var contactlist in Model.Contacts) { @Html.LabelFor(t=>t.ContactNum); @Html.LabelFor(t=>t.ContactType); } ...