entity-framework

Creating Composite primary keys in a many-to-many relationship in Entity Framework

Hello, I have two tables that are connected via a join table in a many-to-many relationship in the Entity Framework. I need to add a composite primary key in the join table for the two columns that are related to the joined tables via standard foreign keys but I'm sure how to do that. ...

If-exists-UPDATE-else-INSERT with Linq-to-Entities?

is there a way to write this same SQL atomic instruction using Entities and LinQ? IF EXISTS (SELECT * FROM MyTable WHERE ID = @Id) UPDATE MyTable SET name = @name ELSE INSERT INTO MyTable (@Id, @name) or do you need to call a stored procedure from within the EF? ...

Why is this Exception?- The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.

I m getting this Exception-"The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects." I ve user table and country table. The countryid is referred in user table. I am getting the above Exception when I am trying to add entry in user table. This is my code- using (MyConte...

Insert record into mysql db with Entity Framework

Hi, the problem is that it will insert a new record in a mysql table, I have already done the mapping of the mysql db and I have already done tests returning data and everything works. Now I read from a file, where there are queries written, I have them run me back and the result of true or false based on the final outcome of single quer...

How can I use table data type in LINQ to Entity

Hello guys, I have a requirement of updating set of N records into the db table at a time. How can I achieve it in LINQ to Entity(.edmx file). If I update them using conventional procedure in LINQ To Entiy, It wont be good practice, How can I achieve this. ...

is there a way to create an item template (t4) installer like the POCO generator?

Subject says it all. I want to modify the POCO generation adapter (at http://code.msdn.microsoft.com/EFPocoAdapter ) to generate my own code. I have the .tt adapters done, but I want to be able to distribute this to coworkers, so they right-click on the model, choose "Generate Code", and my t4 templates appear in the options along with...

Entity Framework not loading in Windows 7

I had to get a new machine recently. It is Windows 7, loaded with Studio 2008, with Framework 3.5 sp1. When I load pre-existing projects that use the Entity Framework, the projects don't recognize the .edmx files. Any ideas? I'm fully patched and running as administrator doesn't make a difference. Opening as XML and saving I have ma...

What are the major limitations of EF4?

Hi, I am trying to decide on an ORM tool for my project, and I am thinking about EF4. What are the major (if any) annoyances/limitations with this product? Also, does it support caching? Thanks ...

LINQ to SQL vs Entity Framework for an app with a future SQL Azure version

I've got a vertical market Dot Net Framework 1.1 C#/WinForms/SQL Server 2000 application. Currently it uses ADO.Net and Microsoft's SQLHelper for CRUD operations. I've successfully converted it to Dot Net Framework 4 C#/WinForms/ SQL Server 2008. What I'd like to do is also offer my customers the OPTION to use SQL Azure as a backen...

what is Entity Framework with POCO

What is the benefit of using POCO? I don't understand the meaning of Persistence Ignorance, what does this mean? That the poco object can't expose things like Save? I can't wrap my head around this POCO that there's alot of buzz around. What is the difference with the EF generated entities and POCO? ...

How to include related Entities using dynamic queries

I am taking the values from a search form in my application to build a dynamic query: string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS Users WHERE "; There are two tables in the database, Users and Photo, table Photo has a column UserId that links to the Users table. A one to many relationship exists between ...

Entity Framework 4 Table Valued Function

Hi, I am aware that table valued functions are not supported in previous versions of entity framework. I was wondering if this is now supported in EF 4? I cant see my functions in the edm designer so i'm guessing they are not supported unless I am doing something wrong? If they are not supported is there a workaround? My table valued f...

Entity Framework Custom T4 Template

Hello, I am using the Entity Framework 4.0 and I am trying to extend my POCO classes generated by the standart T4 template with some custom properties. The classes which are generated by default from EF (without T4) contain 2 properties for every navigation property - NavigationPropertyId and navigationPropertyReference. What I am tryi...

LINQ to Entites: Doing a count over one-to-many relationships

I have a couple of tables where there are one to many relationships. Let's say I have a Country table, a State table with a FK to Country, and a City table with a FK to State. I'd like to be able to create a count of all Cities for a given country, and also a count of cities based on a filter - something like: foreach( var country in ...

Get Newly generated ID (i.e. scopeIdentity) in Entity FrameWork

Hi, I am added a record in my table e.g. Orders. After adding the record i want to get the newly generated ID of the inserted record. Like SCOPEIDENTY in SQL. But how can i do this in Entity Framework. ...

Why does LINQ-to-Entites recognize my custom method?

This works: (from o in Entities.WorkOrderSet select o) .Where(MyCustomMethod); This does not: (from o in Entities.WorkOrderSet select o) .Where(o => MyCustomMethod(o)); ([Edit] Even without new, it doesn't work) I understand why the second doesn't work - but why in the world does the first work!? Shouldn't I get a "LINQ-to-Enti...

Arranging VS2008 generated LinqToSql/EntityFramework data models/contexts in assemblies.

What pattern should I use for data-access in case of VS2008 generated L2s or EF DataModels? Repository-pattern or what? As we know VS2008 generates Data-Models and DataContexts/ObjectContexts in the same file, then, how should I arrange my VS2008 assemblies in my VS2008 solution to achieve a layered design? If I use repository pattern,...

Are EntityFramework generated Entity Persistence Ignorance

So I'm starting to look into EF and POCO. From my understanding, the entity generated by EF is not pure POCO since it inherit from EntityObject. But are they PI? It seem to me that they don't have any persistence awareness in them, or there is something in the EntityObject that makes them PI? ...

Add Entities using EF

It would be great if someone can point me in the right direction on this topic I have the following admx: http://img339.imageshack.us/img339/7817/entitydesignerdiagram2.png And I have to add the (AccData, CntactData, PhnNumber, FnclDetail)entities to the database in one shot What’s the best practices to do the add operation for the a...

Generate Entity Data Model from Data Contract

I would like to find a fast way to convert a Data Contract to a Entity Data Model. Consider the following Data Contract: [DataContract] class PigeonHouse { [DataMember] public string housename; [DataMember] public List<Pigeon> pigeons; } [DataContract] class Pigeon { [DataMember] public string name; [DataMe...