entity-framework-4

How not persist property EF4 code first?

痞子三分冷 提交于 2019-12-17 16:23:55
问题 How do I make non persisted properties using codefirst EF4? MS says there is a StoreIgnore Attribute, but I cannot find it. http://blogs.msdn.com/b/efdesign/archive/2010/03/30/data-annotations-in-the-entity-framework-and-code-first.aspx Is there a way to set this up using EntityConfiguration? 回答1: In EF Code-First CTP5, you can use the [NotMapped] annotation. using System.ComponentModel.DataAnnotations; public class Song { public int Id { get; set; } public string Title { get; set; }

The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects

ε祈祈猫儿з 提交于 2019-12-17 16:14:47
问题 I've read some questions/answers that have to do with this particular error message, but I'm not quite understanding the appropriate solution. I've read many times that you should create the EF4 context, use it, then dispose of it. Throughout my application, I'm loading entities here and there using different context objects, and then eventually want to associate the entities together. I've create a simple console application that easily causes the error. The very simple model is diagrammed

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

Changing Inherited Types in Entity Framework

自古美人都是妖i 提交于 2019-12-17 14:54:17
问题 I see there is a similar question asked here but I don't think it was very clear so I'm creating another : Entity Framework: Inheritance, change object type I have an Entity Student that inherits from an Entity Person. At some point a Person could become a Student. Is there any way in Entity Framework 4 to handle this without a stored procedure or creating a new entity. 回答1: No. The EF inheritance does not support this scenario. The best way to create a Student for an existing Person is to

What causes .Attach() to be slow in EF4?

大兔子大兔子 提交于 2019-12-17 10:44:43
问题 We have a generic update method in our code that does a foreach (var entity in entityList) { Context.GetIDbSet<T>().Attach(entity); Context.SetState(entity, EntityState.Modified); } I'm testing this out by passing in an enumeration of entities and calling this once per entity. What I'm finding is that an enumeration of 1000 entities takes approximately 47s to run. Is that expected behavior? Or is there something wrong with the code snippet? Profiling showed the Attach() method was slower than

Using CreateSourceQuery in CTP4 Code First

旧巷老猫 提交于 2019-12-17 10:01:52
问题 I'm guessing this is impossible, but I'll throw it out there anyway. Is it possible to use CreateSourceQuery when programming with the EF4 CodeFirst API, in CTP4? I'd like to eagerly load properties attached to a collection of properties, like this: var sourceQuery = this.CurrentInvoice.PropertyInvoices.CreateSourceQuery(); sourceQuery.Include("Property").ToList(); But of course CreateSourceQuery is defined on EntityCollection<T> , whereas CodeFirst uses plain old ICollection (obviously). Is

How to convert DbSet in Entity framework to ObjectQuery

假装没事ソ 提交于 2019-12-17 09:53:57
问题 I am using CodeFirst approach and struck with an issue where I need to convert DbSet to ObjectQuery. This is what I did for conversion. ObjectContext objectContext = ((IObjectContextAdapter)db).ObjectContext; ObjectSet<Request> objectSet = objectContext.CreateObjectSet<Request>(); where db is the context inheriting from DbContext and Request is class. So, when I try to call the method that expects ObjectQuery as ObjectQueryMethod(objectSet), it throws the following error. "Type of conditional

Change db table name in EF4 (entity framework 4)

江枫思渺然 提交于 2019-12-17 09:51:33
问题 Does anyone know how to change the mapped db table for an entity in EF4 (entity framework 4)? Later edit: I think i've found the place where the table names are defined, in the model browser. But their names are readonly, so it's not possible to edit them using the designer. Also, there's no reference (from what i've searched) to the table name in the xml schema. 回答1: If you just need to change the name of the table you can: Open EDMX file with XML Editor. Locate SSDL section in it. Locate

Entity Framework - default values doesn't set in sql server table

风格不统一 提交于 2019-12-17 07:49:46
问题 SQL server 2005 database table has a column 'createdon' for which default value set to getdate(). I am trying to add a record using entity framework. 'createdon' column is not getting updated. Did I miss any property in Entity framework, please suggest. 回答1: This is one of the few issues that are problematic with Entity Framework. Say you have a class that looks like this: public class MyEntity { // Id is a PK on the table with Auto-Increment public int Id { get; set; } // CreatedOn is a