entity-framework-4

Entity Framework 4 Abstract Model - How to Programatically Eager-Load Navigational Properties?

∥☆過路亽.° 提交于 2019-12-22 08:24:17
问题 I have an EF4 Model that is built with abstract entities/classes: Notice how State entity has a navigational property called Country . Note: I have lazy-loading disabled, so i must eager-load on demand. Now, if i have the following method: public Location FindSingle(int id) { return _repository.Find().WithId(id).SingleOrDefault(); } This does not return any associations by default. But how can i dynamically eager-load the associations when i explicitly want to? I cannot do this: return

Warning Error 6002: The table/view does not have a primary key defined

扶醉桌前 提交于 2019-12-22 07:48:26
问题 This topic is here several times but no answer give me option how to avoid this issue in EF. My warning: Warning Error 6002: The table/view 'ADContainersWithEnvironmentsView' does not have a primary key defined. The key has been inferred and the definition was created as a read-only table/view. Basicly I'm using database first approach with EF in my project. I have view: CREATE VIEW [dbo].ADContainersWithEnvironmentsView AS WITH ADContainerWithEnvironments(Id, LinkedEnvironmentId) AS ( SELECT

Entity Framework 4: ObjectContext event on successful save

有些话、适合烂在心里 提交于 2019-12-22 06:00:00
问题 Is there a good way to detect when the ObjectContext changes are actually committed? SavingChanges occurs before going to the data store but I also need a way to know if those changes where actually committed. Thanks in advance John Update: What I have is a code first DbContext. This is fed into dynamic data which as I discovered uses the DbContext's internal ObjectContext (to which I have access when casting to IObjectContextAdapter). The dbcontext's SaveChanges is not called, the

WCF data services (OData), query with inheritance limitation?

喜欢而已 提交于 2019-12-22 05:33:50
问题 Project: WCF Data service using internally EF4 CTP5 Code-First approach. I configured entities with inheritance (TPH). See previous question on this topic: Previous question about multiple entities- same table The mapping works well, and unit test over EF4 confirms that queries runs smoothly. My entities looks like this: ContactBase (abstract) Customer (inherits from ContactBase), this entity has also several Navigation properties toward other entities Resource (inherits from ContactBase) I

How to dynamically set a property of a class without using reflection (with dynamic) in C# 4 when property name is coming from another source

笑着哭i 提交于 2019-12-22 05:13:08
问题 I'm building/updating an EntityFramework EntityObject on runtime. I want to set the properties of the entity class, property names and values are coming from another source. So I'm doing this; public static EntityCollection<T> UpdateLocaleEntity<T>(EntityCollection<T> entityCollectionToUpdate, params ILocaleControl[] values) where T : EntityObject { foreach (var x in entityCollectionToUpdate) { Type t = typeof(T); dynamic localeEntity = x; string cultureCode = localeEntity.CultureCode; for

EF4 and Connection String

烈酒焚心 提交于 2019-12-22 04:55:16
问题 I have a 3 tiered project. 1) Project.Data (EDMX file) 2) Project.Model (POCO's) 3) Project.Console (Console app) I have added the connection string into the Project.Console . <?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="ProjectEntities" connectionString="metadata=res://*/Project.csdl|res://*/Project.ssdl|res://*/Project.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PC\SQLEXPRESS;Initial Catalog=Project;Integrated Security

POCO Vs Entity Framework Generated Classes? [closed]

爷,独闯天下 提交于 2019-12-22 04:27:09
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . What are the advantages of using one over the other ? I know POCO classes are more optimal but are they worth the overkill ? And

Entity framework mapping enum : The specified value is not an instance of type 'Edm.Int32' Parameter name: value

ぃ、小莉子 提交于 2019-12-22 04:17:08
问题 I'm trying to return the result of a entity framework query into my own dto class, at the same time as mapping my enum TradeType. I'm getting the following error The specified value is not an instance of type 'Edm.Int32' Parameter name: value Any idea how to fix or a workaround? Thanks public IEnumerable<Trade> GetLiveTrades(string routeName) { return _entities.Price.Where(p => p.StatusCode.Equals("A") && p.Period.PeriodYear <= DateTime.Now.Year+1 && p.Route.RouteCode.Equals(routeName)).

How to use the poco entity generator

纵饮孤独 提交于 2019-12-22 04:04:08
问题 I'm using VS2010, and I've download the C# POCO Entity Generator and installed it, now I want to use it. I can't read the toturial 1 and I can't find any other good toturials, so I've had a go myself - I have created a model and then I'm creating new POCO Entity, but I got the bellow error: Error 1 Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Unable to locate file at

Assigning ids to entities with EntityFramework 4

烂漫一生 提交于 2019-12-22 04:03:47
问题 I'd like to implement "default" Id generation support for my entities. When saving the entity, I'd like EntityFramework to only generate the id value for the Entity if it's not already set. If the ID already has a non-null, non-zero value, I want to have that entity ID preserved when the entity is saved in the database. I'm migrating data from a legacy data model (EntityFramework model created from the old database) to a newly created (model-first) EntityFramework model. Let's call the old