entity-framework-4

EF 4.0 model caching the data, and does not detect the modified data.

Dear All, I am developing ASP.NET application and I have problem with the EF 4.0 model. The EF model detects the newly added and deleted data, but not the modified data from the database. Here is an example of the problem what I have. A- Database: Script to generate the "Employees" database table CREATE TABLE [dbo].[Employees] ( ...

Create a entity data model mapping to pocos that exists in another assembly and different namespaces

I have the following layout in my project (quite simplified): Assembles App.WinClient <--- client App.Service.Api <--- Contains models/businessobjects and service interfaces App.Service <--- service implementation Namespaces I got the following namespace layout in App.Service.Api App.Users (contains User, IUserService etc) App....

EF 4.0 - Load Navigation Property of Navigation Property

I am attempting to perform the LoadProperty operation from my context to load a navigation property of a navigation property. My setup is that I have an EntityA, which contains a list of EntityB's, and each EntityB contains a list of EntityC's. I am doing the following programatically: public virtual List<T> LoadProperty(List<T> entiti...

Inner join and outer join options in Entity Framework 4.0

I am using EF 4.0 and I need to implement query with one inner join and with N outer joins I started to implement this using different approaches but get into trouble at some point. Here is two examples how I started of doing this using ObjectQuery<'T'> and Linq to Entity 1)Using ObjectQuery<'T'> I implement flexible outer join but I ...

EF CTP4: For Code Only, no database generation needed, how much DB info is needed?

I have a database, and I have entity POCO's, and all I want to use EF for is to map between the two and keep track of changes for loading, saving, etc. I have been reading a lot of the literature (such as it is) on "Code First", and I am unclear on how much of the database information I need to supply when there is not going to be a dat...

Entity already participates in another relationship, Entity Framework CodeOnly

I have two objects... and if I compile a program with either one, it works fine, but when they both exist in the same program, I get the exception... *"Entities in 'ObjectContext.UnitSet' participate in the 'Sheet_Statistics' relationship. 0 related 'Sheet' were found. 1 'Sheet' is expected."* class Unit { public int Id; public strin...

Entity Framework 4 - pivot tables and navigation properties

I'm just starting to learn Entity Framework 4, and am a bit confused about how pivot tables enter the mix. Case in point: I'm migrating a video game review site from PHP 5/Kohana framework to ASP.NET MVC 2. I have a few pivot tables to map the many-to-many relationships I have. Example: Video games can be available for several platfo...

Entity Framework 4 Many to Many Binding

The Entity Framework 4 is driving me mad, This situation is: Employee entity - many to many association - Department entity I get employees from the EmployeeRepository and Departments from the DepartmentRepository. Each repository uses its own data context. My UI has a list of departments (from the DepartmentRepository) to select for ...

How to declare one to one relationship using Entity Framework 4 Code First (POCO).

How to declare a one to one relationship using Entity Framework 4 Code First (POCO)? I found this question http://stackoverflow.com/questions/2089395/one-to-one-relationships-in-entity-framework-4-v2-with-poco, but the article that the answer references was not useful (there is one line of code that is a 1-1 relationship, but no mention...

Singleton with Entity Framework : Will Queries run multiple times?

With a model such as ... using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.Entity.ModelConfiguration; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.ComponentModel.DataAnnotations; namespace Singleton { public class Program { public s...

Entity Framework - related ICollection getting materialized into HashSet

I use EntityFramework POCO + proxies + lazy loading in my project. Today I was pretty surprized to see that the class Transaction has its related collection Rows materialized into HashSet (instead of EntityCollection). I need EntityCollection for tracking changes in the collection. public class Transaction { public virtual ICollecti...

Is it possible to see added entities from an unsaved EF4 context?

I'm just getting into Entity Framework 4, and was eventually hoping to wrap it in a repository pattern using POCOs. I discovered something that I wasn't expecting though. It appears that if you create a context, add an object to it (without saving the context) and query the context again, it doesn't include the new object in the results....

How can I improve my business layer objects mapping into a database? Is it time for a O/R mapper?

As I began writing web applications with asp.net I started with small projects that used a Linq-To-SQL mapper for database access to a MSSQL Server. After gaining some expierence I switched into a classic 3 tier with Graphic Layer, Business Layer, Data Layer. The only function of the Data Layer was to provide methods insert/update/delete...

Update relationships when saving changes of EF4 POCO objects

Entity Framework 4, POCO objects and ASP.Net MVC2. I have a many to many relationship, lets say between BlogPost and Tag entities. This means that in my T4 generated POCO BlogPost class I have: public virtual ICollection<Tag> Tags { // getter and setter with the magic FixupCollection } private ICollection<Tag> _tags; I ask for a B...

Can't Get EF4 Eager Loading of Subclassed Entities to Work

I have an abstract Content entity in my EF4 model with a concrete subclass, MultipleChoiceItem. There is a related table in the case of MultipleChoiceItem accessed by a Navigation property on the MultipleChoiceItem entity called Options. I would like to eager-load the Options result because if you're getting a MultipleChoiceItem, you alw...

EF4 CodeFirst CTP4 - Insert with existing association

If I have an entity that has an association (e.g. Book.Publisher), how do I save a new Book and associate it with an existing Publisher? BTW I don't want to expose FK associations (i.e. PublisherId) in my model. I had been using something like this: var book = new Book { Title="whatever", Publisher = new Publisher { Id = 42 } }; cont...

How do I get Entity Framework 4 and WCF Data Services to work with Silverlight 3.0

I have a project that needs to be upgraded in stages. I need to implement Entity Framework v4 first and then eventually upgrade the Silverlight v3 application to v4. Unfortunately my client is not able to roll out Silverlight version 4 until for at least four months (they do want to move to v4 but they have to go though a company wide ...

Identity column in EF 4

I follow by entity framework example : http://msdn.microsoft.com/en-us/library/bb399182.aspx and I have problem with Identity Columns. Here is part of code of creating database: CREATE TABLE [dbo].[Person]( [PersonID] [int] IDENTITY(1,1) NOT NULL, [LastName] [nvarchar](50) NOT NULL, [FirstName] [nvarchar](50) NOT NULL, ...

How to update only one field using Entity Framework?

Here's the table Users UserId UserName Password EmailAddress and the code.. public void ChangePassword(int userId, string password){ //code to update the password.. } ...

Deleting Entities on Entity Framework 4

I'm using Entity Framework 4. I'm detaching the object graph using Serialization. Getting the List, bind to a BindingSource, to the GridControl and deleting adding modify rows. Then go back and Attach the object graph back. How to ensure which rows are for deletion, which are modified, added rows is easy for EF to understand. I'm also th...