entity-framework-4

Entity Framework v4 and Spring .Net

I would like to know if anyone used EF4 with Spring .Net in a WCF service. How easy it is to use DI with EF4 and other pros and cons. Currently I'm using nHibernate as ORM with Spring .Net as a data access layer. Are there good reasons to move to EF4? ...

How to use the DeleteDatabase function in Entities Framework 4?

How can I easily delete all tables from my database (C# ASP.NET MVC 2 using SQL)? I created models to the data with the entities framework and have figured out how to insert data. When I try Entity1 test = new Entity1(); test.DeleteDatabase(); I get this error: Unable to complete operation. The supplied SqlConnection does not s...

ObjectSet query not returning added EntityObject until SaveChanges() called

I think I'm missing something very simple here. I have an EF4 ObjectContext that contains an ObjectSet of type Thing, which is mapped to a table in my database called Things. If I add a Thing to the Things ObjectSet, that Thing is not visible in Things until I call SaveChanges() on the ObjectContext. So, in the following test fixt...

Updating a Detached Entity Instance using Entity Framework 4.0

I am utilizing Entity Framework 4.0 and WCF. I am new to using Entity Framework and am more familiar with NHibernate. However, I am concerned about detached instances of objects when performing an update. I have looked on various websites where they retrieve an object, attach the instance to their context, and set all properties to be ...

Organizing an EF4 data layer?

I am new to Entity Framework 4, and I am wondering, what's the best way to organize my data layer--the code that accesses EF4? At this point, my data layer is set up like this: DataStore class: Holds a reference to the EF4 ObjectContext, and contains methods to open, close, and persist the ObjectContext to storage. Repository classes...

Is there End httpRequest event

I have to share ObjectContext (from EF4) between many objects, so i'm creating one Context per one HttpRequest (i haven't found better way to do this), but there is little problem... When i use using (ObjectContext ctx = new ...) {} it always disposes context after closing bracket. So how should i dealt with it when my context lives...

Cannot delete in EF4

Dear All, I am trying to delete an "AttendeeEvent" from the database with EF4, however I am getting the following error:- The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a nu...

WCF Data Svcs, Silverlight client BeginSaveChanges does not work with stored procedure as UpdateFunction of a View as entity in the entity model?

Hi, WCF Data Services and Silverlight client BeginSaveChanges does not work with stored procedure as UpdateFunction of a View as entity in the entity model? I have specified stored procedure as UpdateFunction in the entity model specified as update function of a view. From the Silverlight client I call WCF Data Service. I also have a M...

Caching Entity Framework EntityTypes

Hi, I have EntityTypes generated from a database using Entity Framework 4. I would like to use Cache to store some of these EntityTypes for performance reasons. Is it safe to do the following provided that the object will be used for read-only actions: context.Students.MergeOption = MergeOption.NoTracking; var students = context.Student...

Entity Framework 4 DDL

I have been using the model-first approach for about two weeks now and it works great. I also used the "Generate Database from Model" option, which results in a DDL being generated, which in turn is an SQL script that I run to create the database. If I add entities to my model and update the DDL it does not add an alter statement to enti...

Entity Framework 4 & Self-Tracking Entities?

I was recently listening to a podcast "herding code" where Julia Lerman was the guest. They were discussing the changes that were made in EF4. They got into the subject of Self-Tracking entities. Julia had said that self tracking entities were not perfect and that they were made for WCF and wouldn't work with asp.net. This is my main que...

Entity Framework 4 Code-First pros and cons

Hi, I would like to know the pros and cons of using EF4 Code-First approach. Can we duplicate all features that EF4 generated classes offer like Lazy Loading, loading related entities, etc? Thanks ...

EF4, Npgsql, M:M relation, "The method or operation is not implemented." :/

Hello I have a problem with many-to-many relation on EF4 and npgsql provider. I have 3 tables: Order, OrderStatus and OrderStatusDict (dictionary). OrderStatus is some kind of changeLog - every order's status change is added to the OrderStatus table with its actual date and new status. I need to get all orders, which status.OrderStatus...

SQL to Entities with inheritance

I have a simple inheritance in my model. The class of an entity is defined by a field (RecordType: int). Now I would like to create a SQL to Entities query where I need to filter only one inherited class. When I use ctx.CreateQuery<InheritedEntity>() it fetches all the classes, rather than only InheritedEntity class. I tried referr...

Does Entity Framework 4 work with SQL Server 2005?

Does ADO.NET Entity Framework 4 work with SQL Server 2005? I'm having trouble getting EF to work and I'm wondering if it's because of our version of SQL Server. ...

Can't resolve problem about EntityClient connection inside VS2010.

This is a strange one, i resolved it once but now i can't think what is missing here. I have a library contains 3 SQL CE databases. I created 3 Entity Framework 4 Models for each database. Then i created a library where contains 4 UserControls, 1 of 3 contains the other 3 Controls, and o drop this one control into the MainForm in the Wi...

How to get first EntityKey Name for an Entity in EF4

Hello, How can I get the 1st EntityKey name for an Entity for Entity Framework 4 because I'm building a repository system and I wanted to get an item by Id (which is the primary key oin EF is the 1st entitykey for the entity) I'm using this code public virtual TEntity GetById(string keyName, Guid entityId) { var ent...

Entity framework 4.0 and inheritance

I want to have an abstract class Employee, and 2 derived classes; Staff and Operative. In my DB design, I have an Employee table and an EmployeeType table. The Employee table contains 2 rows, one with Staff lookup data and the other with Operative lookup data. Using EF4, how do I transform this DB structure into a class design specifies ...

EF4 ASP.NET - Managing Entity Edits between HTTP Posts and Rollback

I am struggling with the following use-case: User amends an existing order. The order is complex - lots of related 'entities' (addresses, post options, suppliers, makes, models, various items etc). Across multiple http posts. User wants to discard the changes. -- I have an order entity and as the user is editing this I am making vari...

Is there a practical way to use the hierarchyID datatype in entity framework 4?

As it stands now, the CLR UDTs including HierarchyID aren't supported in Entity Framework 4. HierarchyID.ToString() is useful, but breaks down once any item has 10+ siblings (the basic structure is /3/4/12/ or /3/4/2/ so the 12th node will sort before the 2nd node). A little more about potential options: Bring back hierarchyID as ...