entity-framework-4

How to ignore entity in Entity Framework Code first via setup

走远了吗. 提交于 2019-12-11 06:37:32
问题 Lets say i have 4 classes: public class Component {} public class SubComponent1 : Component {} public class SubComponent2 : Component {} public class Container : Component { public List<Component> components { get; set;} } And I don't want to store SubComponent2 on database. I want to use it throughout application as normal POCO, only want it to be ignored when trying to save to database. What I have tried so far was to put Ignore for it in my DbContext OnModelCreating method: dbModelBuilder

Is there a way to enforce Entity Framework to read one record from Db at a time while I enumerate?

ⅰ亾dé卋堺 提交于 2019-12-11 06:24:21
问题 Is there a way to enforce Entity Framework to read one record from Db at a time? Basically to make it work like a SqlDataReader (I need to read forward only and I won't change the data at all!) To simplify what I ask with an example, in the loop below, I want EF to obtain 1 city on each iteration. var context = new CityEntities(); var cities = from c in context.Cities select c; foreach (var c in cities) { Console.WriteLine(c); // I want to have only 1 city in the memory at this point } Why :

Entity SQL inner join

本小妞迷上赌 提交于 2019-12-11 06:13:59
问题 I have implement such query using Entity SQL. How i may perform inner join with related entity how may i do this using Entity SQL or Linq to Entity 来源: https://stackoverflow.com/questions/3617229/entity-sql-inner-join

IObjectSet Include Extension Method Errors with CompiledQuery

☆樱花仙子☆ 提交于 2019-12-11 06:07:38
问题 In my Custom ObjectContext class I have my entity collections exposed as IObjectSet so they can be unit-tested. I have run into a problem when I use this ObjectContext in a compiled query and call the "Include" extension method (From Julie Lerman's blog http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-5-iobjectset/): public IQueryable<MyPocoObject> RunQuery(MyCustomContext context, int theId) { var query = CompiledQuery.Compile<MyCustomContext, int, IQueryable

Linq query for EF 4.1 data with nested lists

谁说胖子不能爱 提交于 2019-12-11 05:59:14
问题 I'm working with WPF and EF 4.2 to build a desktop application. I have 3 entities which have cascading one-to-many relationships, Students have zero-or-more schools. Schools have zero-or-more classes attended. I need to display the data in a grouped list showing the student, all their schools then all their classes. Students School Class int Id int Id int Id string Name string Name string Subject int yearBorn string Address int Credits IList<School> IList<Class> I'm stumped by how to shape

VS 2010 EDMX Stored Procedure Missing

痴心易碎 提交于 2019-12-11 05:39:08
问题 Using Visual Studio 2010 SP1, SQL server 2008: Motherboard recently failed and I migrated all my work to a new computer. My project uses entity data model to connect to a sql database. I had everything set up and working before the migration, but now all of the stored procedures have disappeared from the model browser. The function imports are still there, but they obviously no longer work. The problem is, when I go to "Update Model from database" the stored procedures do not display.

Linq to Entities DefaultIfEmpty

旧街凉风 提交于 2019-12-11 05:37:13
问题 I'm using EF 4 to PostgreSQL using a 3rd party ADO.NET provider. In my data source, I have no item lines that match items based on this join condition. For this reason I expect query 1 to fail based on a null reference exception. However, it completes and gives me value type defaults for each of the properties on il. item_display_name is a string so ilName is set to null. ilStartDate is set to DateTime's default. x.il.item_id and x.il.item_line_no are both 0. var query1 = _db.items .GroupJoin

LINQ - recursive request

a 夏天 提交于 2019-12-11 05:36:53
问题 I have the following dataobject: Messages: MessageID int, Text string, ParentMessageID int? so, records like: 1 | "Text 1" | null 2 | "Reply to Text 1" | 1 3 | "Reply to reply to text 1" | 2 ... I need to calculate how many messages in one thread. How to do it by LINQ? 回答1: It's not possible using LINQ to Entities: you would need to write a common table expression to do the recursive query using SQL. These are quite often slow. Assuming you always want to count from the same level in the

Unable to attach multiple entities for insertion (An object with the same key already exists in the ObjectStateManager)

痴心易碎 提交于 2019-12-11 05:34:00
问题 I have an entity that contains a list of other entities. The list of entities contains a primary key (identity), foreign key and a string. When I try to attach the parent entity, I get the exception An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key . For some reason the Entity Framework (EF) thinks that this is a duplicate record. The records do have the same foreign key , but property that is the

A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column:

一笑奈何 提交于 2019-12-11 05:28:31
问题 First, thanks for taking the time to read this. I'm having some difficulties with trying to update a database using EF. I've used this same approach before on another project, so I'm thinking the issue is perhaps in the database, but I'm just not seeing it. The database is a legacy db in SQL 2005, and the naming convention has a lot to be desired, therefore I've been mapping the inconsistent names to something more consistent via the HasColumnName method: as in. modelBuilder.Entity<Case