entity-framework

Succinct But Complete Example of WPF App?

Is there a succinct but complete example project or tutorial that brings together the pieces of the Microsoft stack for a complete application? WPF MVVM Business Objects EF Database I find plenty for WPF and plenty for EF, but am having trouble fully understanding how the EF generated classes relate to business objects, and how thos...

AddObject necessary in Entity Framework?

I'm using Entity Framework (1st time) on a SQL 2005 database for a data migration and found this very odd behavior... Up till now I never had to call the AddObject method to persist new records. SaveChanges always did the trick, so I figured the entity constructor always hooked the new entity to the data context. Now I added migration ...

WCF Data Services: Call to SaveChanges() causes 100% CPU

I am developing a WCF Data Service over an Entity Framework 4.0 data model, but there's no way we can go to Production under the current circumstances. My client application is adding and modifying a lot of objects, around 100,000. Then it calls the service's SaveChanges method to persist all changes in a single action. The WCF Data Ser...

Entity framework : [Set all the entities with internal access specifier]

Hi, By virtue of my application, I need to seperate my business entities from the entities created by EF4. I need to restrict the entities to only access the repository from where they are translated (using translator) to business entities shared at business and service layer. I thought of restricting them by specifying them as internal....

Entity Framework .Include() with compile time checking?

Consider the following code, which is calling against an EF generated data context: var context = new DataContext(); var employees = context.Employees.Include("Department"); If I change the name of the Department relationship then this code is going to start throwing a runtime error. So is there any way to call the .Include() method...

Joining a Many to Many table.

I have a situation where I am providing a method to query for data in various ways. We provide the user with 4 different fitler criteria and they can mix and match as much as they want. For example: public Fruit GetFruit(Boolean isLocal, string storeName, string classificationType, string state); This is simple when all of the attr...

Entity Framework Custom Query Function

I have an Entity Framework 4.0 Entity Object called Revision w/ Nullable DateEffectiveFrom and DateEffectiveTo dates. I was wondering if there was a short-hand way of querying an object's RevisionHistory based on a particular QueryDate date instead of having to use the following query structure: var results = EntityObject.Revisions.Wher...

Lazy Load An Entity Framework EntityCollection with criteria

In Entity Framework (specifically EF 3.5, but if it exists in EF 4 it gives me a reason to upgrade) is it possible to lazy load only part of a collection? I may be approaching this wrong too, so I'm open to suggestions. My tables/entities look similar to this: Person PersonMeal Meal ------ 1---* ---------- ...

If I select from an IQueryable then the Include is lost

The include does not work after I perform a select on the IQueryable query. Is there a way arround this? My query is public IQueryable<Network> GetAllNetworks() { var query = (from n in _db.NetworkSet .Include("NetworkContacts.Contact") .Include("NetworkContacts.Contact.RelationshipSource.Target") ...

Using an existing IQueryable to create a new dynamic IQueryable

I have a query as follows: var query = from x in context.Employees where (x.Salary > 0 && x.DeptId == 5) || x.DeptId == 2 order by x.Surname select x; The above is the original query and returns let's say 1000 employee entities. I would now like to use the first query to deconstruct it and recreate a new query that would...

Is there a way to get the "FromProperty" of the System.Data.Metadata.Edm.NavigationProperty?

On EF4: e.g: I have a SystemRole entityType that has a SystemUsers navigation property, and SystemUser entityType has a SystemRoles navigation property, the association is from SystemRole.SystemRoleId to SystemUser.SystemUserId. My question is: Is there a way to get the "SystemRole.SystemRoleId" & "SystemUser.SystemUserId" from the sp...

Query data using LINQ to SQL and Entity Framework with foreign key? (Help me please)

Hello! There is a problem I need help with your query on the data using LINQ to SQL and Entity Framework (I'm using Visual Studio 2010). My picure here: http://img.tamtay.vn/files/photo2/2010/5/28/10/962/4bff3a3b_1093f58f_untitled-1.gif I have three tables: tbl NewsDetails tblNewsCategories tblNewsInCategories (See screen 1 in my ...

Which .NET data provider?

I am new to database programming, so I'd like help getting on the right track. I have read that there are Microsoft-defined and third-party data providers for data access. MSDN has information on data providers for SQL Server, OLE DB, ODBC, Oracle, as well as the EntityClient provider (Entity Framework). Which data provider is today's ...

Entity Framework 4: Cannot map multiple many-to-many relationships to the same storage 'join' tables

Hi I have a table that uses TPH to provide multiple entity types. I also have a join table with two columns, both as foreign keys to the other table. I am using this join table for many-to-many relationships on one of my entities and it works OK. However, if I use it for another many-to-many relationship in another entity (an entity t...

Unable to specify abstract classes in TPH hierarchy in Entity Framework 4

Hi I have a TPH heirachy along the lines of: A->B->C->D A->B->C->E A->F->G->H A->F->G->I I have A as Abstract, and all the other classes are concrete with a single discriminator column. This works fine, but I want C and G to be abstract also. If I do that, and remove their discriminators from the mapping, I get error 3034 'Two ent...

Entity Framework 4.0 GetChanges() equivalent

Hi In LINQ to SQL, you can override SubmitChanges and use the method this.GetChangeSet() to get all the inserts, updates and deletes so that you can make last minute changes before it is committed to the database. Can this be done in EF 4.0? I see there is a override for SaveChanges but I need to know the equivalent for GetChangeSet()...

Many to Many relationship in EF

Hi, I have what seems to be a simple question about EF 1.0 and have been looking all over the web for a simple answer, but have had no luck so far: We're about to build a small application with SQL Server as the backend and have been considering using EF 1.0. Our company, like many large corporations, does not move quickly in adopting ...

LINQ to Entities projection of nested list

Assuming these objects... class MyClass { int ID {get;set;} string Name {get;set;} List<MyOtherClass> Things {get;set;} } class MyOtherClass { int ID {get;set;} string Value {get;set;} } How do I perform a LINQ to Entities Query, using a projection like below, that will give me a List? This works fine with a...

Entity Framework 4 Entity with EntityState of Unchanged firing update

I am using EF 4, mapping all CUD operations for my entities using sprocs. I have two tables, ADDRESS and PERSON. A PERSON can have multiple ADDRESS associated with them. Here is the code I am running: Person person = (from p in context.People where p.PersonUID == 1 select p)...

EntityFramework performance problem

I'm using EntityFrameowrk 4 and WinForms. I have a DataGridView which shows 5 to 12 thousands of records. The records are from different levels of hierarchy. There are records of classes A, B, C, D, where A contains a collection of B, B contains a collection of C, etc. The most numerous class is D. In the DataGridView this hierarchy is f...