poco

Entity Framework: Tracking changes to FK associations

Deadly 提交于 2019-12-18 01:21:32
问题 I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title

EF CTP5 - Strongly-Typed Eager Loading - How to Include Nested Navigational Properties?

…衆ロ難τιáo~ 提交于 2019-12-17 22:14:21
问题 Attempting to cutover our EF4 solution to EF CTP5, and ran into a problem. Here's the relevant portion of the model: The pertinent relationship: - A single County has many Cities - A single City has a single State Now, i want to perform the following query: - Get all Counties in the system, and include all the Cities, and all the State's for those Cities. In EF4, i would do this: var query = ctx.Counties.Include("Cities.State"); In EF CTP5, we have a strongly typed Include, which takes an

Onion Architecture- Entity Framework Code First Models DataAnnotations

泪湿孤枕 提交于 2019-12-17 18:43:51
问题 I am developing a ASP.NET MVC Project following the Onion Architecture. I have added the Models inside my Core Project and these Models will be referred as the POCO classes for the Entity Framework Models in the Infrastructure Project. My question is how can I add Data Annotations Which depends on the Entity Framework? Can I make the Core Models as Interfaces and inherit it in the Infrastructure Projects and do real Implementation? 回答1: You don't need to create Core Models as Interfaces if

Entity Framework 4: Does it make sense to create a single diagram for all entities?

心不动则不痛 提交于 2019-12-17 15:22:49
问题 I wrote a few assumptions regarding Entity Framework, then a few questions (so please correct where I am wrong). I am trying to use POCOs with EF 4. My assumptions: Only one data context can exist for an EF diagram. Data Contexts can refer to more than one entity. If you have two data sources, say MS SQL server and Oracle, EF requires two different diagrams to access the data. The EF diagram data context is the "Unit of Work", having a single Save() for anything on the diagram. (Sure you

Entity Framework 4: Does it make sense to create a single diagram for all entities?

末鹿安然 提交于 2019-12-17 15:18:46
问题 I wrote a few assumptions regarding Entity Framework, then a few questions (so please correct where I am wrong). I am trying to use POCOs with EF 4. My assumptions: Only one data context can exist for an EF diagram. Data Contexts can refer to more than one entity. If you have two data sources, say MS SQL server and Oracle, EF requires two different diagrams to access the data. The EF diagram data context is the "Unit of Work", having a single Save() for anything on the diagram. (Sure you

Why is my Entity Framework Code First proxy collection null and why can't I set it?

蹲街弑〆低调 提交于 2019-12-17 08:32:51
问题 I am using DBContext and have two classes whose properties are all virtual. I can see in the debugger that I am getting a proxy object when I query the context. However, a collection property is still null when I try to add to it. I thought that the proxy would ensure that collection is initialized. Because my Poco object can be used outside of its data context, I added a check for the collection being null in the constructor and create it if necessary: public class DanceStyle { public

Why is my Entity Framework Code First proxy collection null and why can't I set it?

♀尐吖头ヾ 提交于 2019-12-17 08:32:23
问题 I am using DBContext and have two classes whose properties are all virtual. I can see in the debugger that I am getting a proxy object when I query the context. However, a collection property is still null when I try to add to it. I thought that the proxy would ensure that collection is initialized. Because my Poco object can be used outside of its data context, I added a check for the collection being null in the constructor and create it if necessary: public class DanceStyle { public

Exclude a field/property from the database with Entity Framework 4 & Code-First

北慕城南 提交于 2019-12-17 06:37:13
问题 I will like to know that is there a way to exclude some fields from the database? For eg: public class Employee { public int Id { get; set; } public string Name { get; set; } public string FatherName { get; set; } public bool IsMale { get; set; } public bool IsMarried { get; set; } public string AddressAs { get; set; } } How can I exclude the AddressAs field from the database? 回答1: In the current version the only way to exclude a property is to explicitly map all the other columns: builder

Generate POCO classes in different project to the project with Entity Framework model

给你一囗甜甜゛ 提交于 2019-12-17 04:26:51
问题 I'm trying to use the Repository Pattern with EF4 using VS2010. To this end I am using POCO code generation by right clicking on the entity model designer and clicking Add code generation item. I then select the POCO template and get my classes. What I would like to be able to do is have my solution structured into separate projects for Entity (POCO) classes and another project for the entity model and repository code. This means that my MVC project could use the POCO classes for strongly

Generate POCO classes in different project to the project with Entity Framework model

冷暖自知 提交于 2019-12-17 04:26:10
问题 I'm trying to use the Repository Pattern with EF4 using VS2010. To this end I am using POCO code generation by right clicking on the entity model designer and clicking Add code generation item. I then select the POCO template and get my classes. What I would like to be able to do is have my solution structured into separate projects for Entity (POCO) classes and another project for the entity model and repository code. This means that my MVC project could use the POCO classes for strongly