entity-framework

How To Handle Concurrency Using An ORM

Suppose I was writing an application where users had to book appointments (in my case, a user is paired with an employee and that employee will do work for that user at a particular time of day). How would I ensure that 2 users did not end up booking the same appointment using NHibernate or Entity Framework? Would I open a transaction an...

How Refactor Code/DB schema with EF 4 code first - Data Migration

What are the best practices for database refactoring with codefirst EF4? I am interested to hear how people change the classes and the database when the RecreateDatabaseIfModelChanges option is not feasible. Migration of data will need to occur. Currently Microsoft has a solution for doing this with model first: http://blogs.msdn.com...

Entity Framework - An item with the same key has already been added. - Error when trying to define foreign key relationship

I have an entity with a foreign key relationship to an asp.net membership provider users table. This portion of the model looks like this: I can't seem to assign the foreign key relationship when inserting the Users table record, the record containing the foreign key to the aspnet_Users table. I keep getting the error: An item w...

how to update an entity in Entity Framework 4 .NET

my code is something like this: public class Program { [STAThread] static void main() { DataAccessClass dal = new DataAccessClass(); List<Person> list = dal.GetPersons(); Person p = list[0]; p.LastName = "Changed!"; dal.Update(p); } } public class DataAccessClass { public static List<Person> GetPersons() { MyDBEntitie...

Organize my domain objects in DDD while using ado entity framework

I have these 2 types of Users: Parents and Kids, both are Users, and have the same properties, but different methods. I Created Base User class and 2 class: Parent And Kid, both inherit form User base class, and each class have some different methods. User class is partial class, because the entity framework model has the same class bec...

Custom property in partial class doesn't exist AFTER it's sent to client using WCF Data Services

So I have an Event class which is generated from Enitity Framework, I have extended what it generated in a partial like so: public partial class Event { [DataMemberAttribute()] public EventDate CurrentEventDate { get; set; } } When I use the custom property ON THE SERVER it's fine, example: [WebGet] public IQueryable<...

How not persist property EF4 code first?

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? ...

Does EF update objects just because a property changes or only if it has a different value?

I have an import, from flat file to an EDM against SQL Server, where very few records actually change (running it the umpteenth time with the same import file), but nonetheless the SaveChanges call to update 500 records takes quite long. I'm guessing this is because I set each property on the entity object, and EF then uses ReportProper...

How map objects to a view with EF 4 code first?

How can you map an entity to a database view with EF 4 code first? Is there a way to do this by deriving from the EntityConfiguration classes? ...

Does EF have ordered collections? The equvilant of list in the NHiberante Bag Vs Set Vs List world

Does the Entity Framework 4 have ordered collections? For example my Order has a property that is a collection of OrderItems, but the order is important and I would rather not sort them before I access them. See Nhibernate for an example: http://stackoverflow.com/questions/1916350/set-bag-and-list-set-in-nhibernate ...

how to convert the <T> to its base type for generic method?

Hi all I have a generic CRUD class to perform add, delete, select, create to my entity objects. one of them - Message has two derived classes - order_message , and report_message. My problem is that in my generic class, I need an objectset to perform crud ops, but objectset does not accept a derived class type, it only accept base cla...

Are nullable foreign keys allowed in Entity Framework 4?

I have a problem updating a foreign key in an Entity Framework entity. I am using self tracking entities and have an entity with some relations where the foreign key is also present as a property (one of the new features of EF4). The key (an integer) is marked as Nullable and Concurrency Mode fixed. Specifically I have an Alarm entity w...

Problem with Entity Framework in WPF Application

Hello again, I am having a problem with a SQL server database in my WPF application. The database is in a separate class library project and I am using Entity Framework. The problem arises when I try and deploy this using ClickOnce in which the following error occurs: "Underlying Provider failed to open" I tried to solve this by moving ...

Entity Framework - Expecting non-empty string for 'providerInvariantName' parameter.

Ok, this may not be related to EF. I am trying to use the code-first feature and following is what I wrote:- var modelBuilder = new ModelBuilder(); var model = modelBuilder.CreateModel(); using (AddressBook context = new AddressBook(model)) { var contact = new Contact {...

Entity Framework 4 - Code First and Stored Procedures

Hi, I want to execute stored procedure with one parameter that returns table using EF4 "Code First". I am ok with some DTO just for this purpose, it doesn't have to return entities. I have tried to: a) create edmx file with function import and add it to my ObjectContext like this: protected override void OnModelCreating(ModelBuilder m...

Partial Class Properties not accessable through LINQ query bound to GridView

I have added a partial class to one generated by the Entity Framework. I wanted to add a calculated field that I could bind to my GridView. However, when I try to access the new property, I get an error message that this is a limitation to Entity Framework. Are there any work arounds to accomplish this? ...

Wrong object added to ObjectContext (_addedEntityStore)

I have a wizard in my asp.net MVC application which is built upon this SoG - RESTFUL wizard guide. In order to understand the problem I will first explain the situation below. For this I will use a dummy situation, we try to create a person with an address. Again, this is just a dummy situation! The situation At start, the object (pe...

Transforming Entity Framework EDMX File with XSLT

I would like to make some changes to my EF4 edmx file without modifying the file itself, mainly so I don't loose all my changes if I regenerate the model from the database. I'm familiar with XSL and have seen references made to using it in conjunction with the edmx file. This sounds like a great solution, however I can't seem to find any...

Entity Framework: Exclude columns from the selection in Entity Framework?

Hi! I want to have an ObjectQuery that returns tracked entities (not static data), but I don't want it to load all the columns, I want some columns to load as null, I don't want to use select, since this will return an IEnumerable of the values, not tracked objects. Is there a way to do it? If yes, how do I then complete reloading tho...

Entity Framework - Cascade Delete not getting set in Entity Model

I am using EF 4.0 and am generating my Entity Model (.edmx) file from my database. I have several foreign key constraints for Cascade OnDelete, however, these are not getting set on my associations in my entity model. I click on the association and it shows End1 OnDelete: None. When I check the Delete rules in my SQL Server 2008 databa...