entity-framework-4

Generic repository select by ID in EF4

So I'm trying to create a generic select by ID method for a base repository class. In order to achieve this I'm using EF4 with POCO's. I created an interface with a getter called Id and successfully modified the T4 template in order to have a generic Id property in all the entities that returns the PK. The problem comes when I use the q...

entity framework 4 IObjectSet include

I am using EF4 CPT4 Code first and I have setup my ObjectContext to return IObjectSet so I would be able to Mock and test my repos. However, I now noticed that I am unable to use the .Include() method for eager loading like I would be able to if I used ObjectSet. Is there a way to make this work??? Edit: I added this extension method:...

Entity Framework 4: Math.Sin()-function

Hi community, is there an possibility to call the Math.Sin()-function in a Linq To Entites (Entity Framework 4) -Query? I've read, that the current Entity Framework 4 doesn't implement this function. Maybe there's a workaround to this solve problem? (I don't want to invite all entries in the memory.) Thanks and best regards ...

EF4 Mapping one-to-many on existing database without navigation

I'm using ModelBuilder to map an existing database to POCOs. I have courses, students, and meetings. Here are the tables CREATE TABLE Courses ( CourseID int, Name string) CREATE TABLE Students( StudentID int, Name string) CREATE TABLE Courses_Students ( CourseID int, StudentID int) CREATE TABLE Meetings ( ...

Does Entity Framework 4 support Many-to-Many queries?

I have the exact same problem as described in this post (event content / tags objects): http://stackoverflow.com/questions/110314/linq-to-entities-building-where-clauses-to-test-collections-within-a-many-to-ma#131551 I am getting the Exception: Unable to create a constant value of type 'XXX.Tag'. Only primitive types ('such as Int32, ...

Reading, incrementing and writing back a counter which is unique across multiple users (in EF 4)

I have a database table and a corresponding entity class (POCO with change tracking Proxy) with a member which acts as a counter: class MyEntity { public virtual int ID { get; set; } public virtual int Counter { get; set; } } There is a function in my web application which must fetch this entity by ID, read the Counter (which ...

Using Entity Framework, how do I add a record to the mapping table in a Many to Many relationship

I have the following tables (condensed for readability): Call ID CallerName CallerTime Categories ID CategoryName CallCategories CallID CategoryID When I modeled these in the Entity Framework the mapping talbe "CallCategories" was left out. I am stumped on how to get a record added to this table via the EF. I have gotten this far...

Why does entity framework pluralize and capitalize entity class names?

Why does entity framework pluralize all the class names and capitalize the first letters by default? What are the advantages of doing this ? Probably a stupid question...but just out of curiosity? ...

Testing Controllers and EF4 without POCO?

Is thera any good way to write Unit Tests for controllers and EF4 without POCOs? I have few repositories, controllers with injected repos and i'd like to write some unit tests (i know, tests should be written before, but noone's done it). To test controller i have to mock HttpContext etc. and inject repo with Mocked ObjectContext gener...

More than one developer using the entity frame 4 .edmx file at any given time

Hi, I am using EF4. Just a quick question, is this a really good framework? We currently make use of a business and data layer as separate projects. The fact that everything is in 1 file in EF4 is this a good thing? How do you distinguish between your business and data layer? How is it possible for more than 1 developer to work on ...

How to get to the primary key of a self tracking entity?

I am trying to create a generic method that will retrieve an item by its id: public T GetByID(int id) { return (T) context.GetObjectByKey( new System.Data.EntityKey(context.DefaultContainerName + "." + context.CreateObjectSet<T>().EntitySet.Name, "ProductID", id)); } Basically I am able to infer ...

How do I create a One-to-One relationship in Entity Framework 4

I am struggling to create a One-to-One relationship in EF4.I keep getting errors like this: Each of the following columns in table XXX is mapped to multiple conceptual side properties: XXX.Id is mapped to <XXXYYY.YYY.YYYId, XXXYYY.XXX.Id> Given I have a classes Person and PersonDetail that relate to tables of the same name, and the Id'...

Error 2010: The Column 'ChildID' specified as part of this MSL does not exist in MetadataWorkspace

I've got an Entity Framework 4 EDMX using Table Per Type inheritance between one base table and two inheriting tables that looks something like this (table names changed and a lot of unrelated stuff removed). <edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx"&gt; <!-- EF Runtime content --> <edmx:Run...

Can i join the list object in .NET collection with the enity object in EF

Can I join the list object in .net collection with the enity object in EF for example var prodts = from req in Product join prod in context.ProductApplications on req.ProductGUID equals prod.ProductGUID slect req; Product is the lsit object. and context.ProductApplications is the Enity object. Can I j...

Does Entity Framework 4 support Batch Inserts?

I found this similar question here, but this is really old. Was it implemented in the latest version? ...

Navigation Property Null after query in CTP4 Code First EF4 Feature

Hi, I just started playing around with the CTP4 and Code-First. I have the following setup for a possible dating site: public class User { [Key] public int Id { get; set; } [Required] public string LoginName { get; set; } [Required] public string Firstname { get; set; } [Required] public string Lastname {...

WCF Data Service SaveChanges problem

I've published wcf dataservice project to IIS7 with .NET 4 installed on that server. Everything worked fine, but when i called SaveChanges from client, service returned error: Server Error in '/' Application.Description: An error occurred while accessing the resources required to serve this request. You might not have permiss...

Entity Framework - how to raise OnChanging for any property?

In a WPF / EF4.0 / MVVM app I have a View that edits a Customer entity. What is the best way to set a property "bool IsCustomerInEditMode" in my CustomerViewModel short of acting upon OnChanging/OnChanged partial methods for every single individual property of the Entity? As far as I know there's no OnEntityChanging method... Thanks! E...

Way to make EF include method generate inner joins?

Using EF4. I have a situation where a linq to EF query with explicit joins won't work due to a many-to-many table. I'm not going to break the database design to suit EF, so I want to use the include method. However, that always seems to generate left outer joins and I need inner joins (simple context.Table1s.Include("Table2") where tab...

Data Grid View Combobox

I am using entity framework 4 and Csharp. I have a datagridview in a windows form. The datagridview has a colomn with a combobox. The combobox is to hold an Entity object. Usually I do the following: dataGridViewComboboxColumn.DisplayMember = "DisplayThis" dataGridViewComboboxColumn.ValueMember = "DisplayThisId" But I want: data...