entity-framework

How do I bind multiple tables (or entities) to a datagrid and enable CRUD operations?

Hi all, Consider two tables, Product and Supplier. To get the required data for a grid view I need to do something like the following code snippet. SupplierID is a foreign key in the products table, but needs to be displayed in the user friendly SupplierName from the Supplier table. SELECT Product.ProductID, Product.ProductName, Produc...

How to Add existing entity as a new Entity with Entity Framework

I want to create a copy my object in my DB with using Entity Framework first I got my "Book" from DB var entity1 = new testEntities(); var book= entity1.Books.First(); entity1.Dispose(); then, I tried to add this object as a new object var entity2 = new testEntities(); book.Id = 0; entity2.SaveChanges(); entity2.Dispose(); Also I ...

Entity Framework 4 POCO Context Persistance Accross Services

I have a WCF service that uses the entity framework to retrieve records from the database and map them to POCO objects. These POCO objects are then returned to the client application. Lets say the client application changes some properties on one of these POCO objects then sends it back to the WCF service to be saved. As far as I can se...

Is LINQ the primary query method of Entity Framework?

I'm just starting with Entity Framework and there's a thing I don't understand: They say LINQ to SQL is being discontinued. But Entity Framework is being activelly developed and recently they released version 4.0. As far as I know, LINQ is the default method of expressing queries in Entity Framework. How come? What are they gonna do? Th...

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

Entity Framework 4 Code First Custom table mapping Fluent API issue

First some brief background: I have an existing ASP.NET MVC 1 application using Entity Framework v1 which works fairly well, though because there are getting on to 40 tables the .edmx is getting unwieldy and prone to corruptions with the Visual Studio 2008 designer. What I want to do is to see if it's feasible to migrate the DAL to use ...

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

Why is a datasource not created for one of our EF models?

We have a Model project with 4 EF models in it. Notice the properties folder starts out empty. With the Model project selected I open the data sources window. Three datasources are created and displayed. You can see how it creates a .datasource file for each model, except the eFinancials model. Any ideas why this happens. There i...

EntityReference can have no more than one related object.

I have two identical controller actions and two nearly identical views (one just has a different javscript file with it). One view works just fine, but the other gets hung up on this EF error: A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned mo...

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

How do I make my component entity system thread safe?

I am currently integrating an entity component system, as seen here, with a physics engine and a graphics engine. This was all fine until recently deciding that the physics should be running in its own thread. (Thanks Glenn Fiedler!) As it is now I am simply locking a mutex shared by all subsystems when accessing components. Snippet fr...

WCF Data Services UpdateObject not working

Hi, I have a Silverlight client with a grid getting data from WCF Data Service. Works fine. However if I want to update some changed grid row, the service data context UpdateObject is not working: DataServiceContext.UpdateObject(MyGrid.SelectedItem); foreach (Object item in DataServiceContext.Entities) { // } ...

WCF Data Service Versioning with EF

I have multiple clients and a central server. The server is using a WCF data service to allow clients to update data. An EF Model interfaces the server Data services. Clients use the below code. svr.AddToTable(NewData) svr.SaveChanges() I need to let the server DB add columns to tables and allow clients to continue to work with the d...

Inheritance of database tables in VS

I want to create Table-Per-Type database table inheritance. Simply base table RowElement will have 2 children tables. First child table Lyrics will inherit all parents RowElement's columns and will just add one more column. Second child table ChordUse will only many-to-one relationship to table Chord. This is how my database schema lo...

How to get ObjectSet<T>'s entity key name?

I've created a generic ObjectSet<T> in my generic repository. What I would like to get is the name of the EntityKey of ObjectSet<T> so that I can use it in the DataContext.GetObjectByKey. I've searched around and dug deep, but I can't seem to find this value anywhere in the ObjectSet class. ...

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

Using IDENTITY_INSERT with EF4

I am trying to create a record in the db that has a predefined primary key value. I know how to do this with sql, but I was wondering if EF can do this for me? Otherwise, I will have to create a stored proc for the inserts. ...

How can you retrieve all records of certain subtype dynamically with Linq to Entities?

I am trying to get a list of all objects in the database of a specified type. I have done this before when the type was known at compile time, but now I am trying to pass a type into the method and have the method return all the records of that specified type, and I can't get it working. I have tried the following: public IList<W...

Get Objects from an ObjectSet by specifying a Range in EF

Hi all, I am trying out EF 4.0.I have an Employee Object and using EF I am getting the Employee ObjectSet by simply calling Context.Employees Now the above call will spit following sql query select * from Employees The above query works fine and I don't have any complains on it however as you know this will not be performant...