entity-framework-4

Unit testing with EF4 "Code First" and Repository

I am attempting to get a handle on Unit testing a very simple ASP.NET MVC test app I've built using the Code First approach in the latest EF4 CTP. I'm not very experience with Unit testing / mocking etc. This is my Repository class: public class WeightTrackerRepository { public WeightTrackerRepository() { _context = ne...

Import serialized Entity into context and keep the original EntityKeys

Hi - I'm serializing an entity from an EF 4 context which has a GUID primary key. Works fine, everything is serialized into an XML file which is transmitted to another computer. There I need to get the object exactly as it is into the database on this host. And this is where things don't work anymore. When I deserialize the entity and...

How to deploy SQL CE 4 CTP to shared hosting?

How do I deploy SQL CE 4.0 with EF4 to a shared hosting provider for ASP.NET MVC 2.0? I've included System.Data.SqlServerCe.dll, and the amd64 + x86 directories in my bin folder, but keep getting a ".net provider not found". I realize it's currently in CTP, but this is just for testing purposes. My project + host is configured for .net ...

Entity Framework 4 Error: Unable to update the EntitySet because it has a DefiningQuery

Okay, here's the scenario. I have 3 tables. One called aspnet_Users one called Categories and a linking table called User_Categories. aspnet_Users and Categories both have primary keys (UserId and ID respectively). The linking table has only two columns: CategoryID and UserId, and there are foreign key relationships setup for each co...

Is DbContext the same as DataContext?

I'm following a tutorial by Scott Gu that refers to a class named DbContext. I can't find it on any namespace on framework 4 and it seems to me it was renamed from CT4 DbContext to .net4 System.Data.Linq.DataContext. Is my assumption correct? ...

How to determine which entity failed on SaveChanges

I have a number of pending changes in my object context when I call SaveChanges. Somewhere in there is an entity with a value for a column that is too long. This results in SqlException: String or binary data would be truncated. The question is how do I determine offending entity/column? ...

Loading a Child (Navigation Property) Entity not working

I am having a very tough time with this one. I have a Navigation property called Attachment that is part of an entity called ContentChannel. ContentChannel is a many to one relationship with KioskType. In my domain service extension class, I have the following query: public IQueryable<ContentChannel> GetContentChannelFromKioskType( l...

How to dynamically set a property of a class without using reflection (with dynamic) in C# 4 when property name is coming from another source

Hi, I'm building/updating an EntityFramework EntityObject on runtime. I want to set the properties of the entity class, property names and values are coming from another source. So I'm doing this; public static EntityCollection<T> UpdateLocaleEntity<T>(EntityCollection<T> entityCollectionToUpdate, params ILocaleControl[] values) ...

Selecting Ids in entity framework?

How do I select all Ids in any entity query as a List? Let say I have an entity with 2 properties (int)Id (any type)(property) How do I select all Ids in query as a List? ...

SL4 WCF RIA Query Issue: "Completed" happening before it's really completed?

I have a strange little issue with a WCF RIA service I'm using in a SL4 application. Here is the code for a button click handler I've got: private void btnTest_Click(object sender, RoutedEventArgs e) { LanguageContext context = new LanguageContext(); LoadOperation<Language> op = context.Load(context.GetLanguagesQ...

storing entity framework self tracking entities in asp.net session, good idea?

let us assume that I have a reusable business layer that further makes use of a data access layer that was implemented using Entity Framework 4.0. The entities returned/consumed by the business layer are self-tracking, allowing us all the goodies that come with those type of entities. I would like to be able to store the entities I wor...

Self Tracking Entity - Loading Navigation Property of a Navigation Property

I am curious what the best practice is for this situation in Entity Framework 4.0. I have the following Entity Map: Entity A -> Entity B -> Entity C Where Entity A contains a list of Entity B's which each contains a list of Entity C's. I am using self tracking entities and when I load Entity A I am doing something similar to this: Ent...

Naming conventions in generated many-to-many table using EF4 CTP4 code first approach

Given the following POCO classes: public class Certification { public int Id { get; set; } public virtual ICollection<Employee> CertifiedEmployees { get; set; } } public class Employee { public int Id { get; set; } public virtual ICollection<Certification> Certifications { get; set; } } Creating the database model usi...

Running SQL Server full-text search statements from Entity Framwork

Essentially, it's a rehash of this question for Entity Framework 4. http://stackoverflow.com/questions/534356/how-do-you-do-full-text-search-fts-with-linq-to-ado-net-entity-framework At this time we are using SqlDataReader where we submit a query with ... WHERE FREETEXT(description, "value). However, as we are moving to EF4, I would pre...

EF4 Model-First entities "non-partialable" when used in separate project.

I cracked open the tekpub EF4 series last weekend and replaced my subsonic stuff that I started with on a new site. I was a little miffed to find however, that with my entities in a separate domain project, I could not "partial" the entities on my MVC2 app. I did the awful thing of putting my EF4 model right in my app and then it worked ...

How does Entity Framework relate a custom POCO to a table?

I am attempting to add a new EF4 POCO to an existing solution. I am getting following error, and when I look at existing POCO already created in the solution I cannot work out how the link is made between the POCO and the table. Mapping and metadata information could not be found for EntityType 'XXX.Run'. Here is an example of one ...

Entity Framework 4 Lazy Loading When It's Not Needed; Using Wrong Key

I have a problem in EF4 where a query that I have returns the data that I want into an anonymous type, but when I try to move the data into a "real" type (I'm creating new instances of my EF objects) some data that the code has already pulled down from the database gets lazily loaded and for the lazy load it's using the key from the prev...

Entity Framework 4 Single() vs First() vs FirstOrDefault()

I'm having a devil of a time finding a comparison of the different ways to query for a single item, and when to use each. Does anyone have a link that compares all these, or a quick explanation as to why you would use one over the other? Are there still more operators that I am unaware of? Thank you. ...

Query EntityCollection

Hi I've mapped my classes with default EF way, and all my FKs are EntityCollection, so for example Bike.Wheels would be EntityCollection. How do I work with Wheels: I want to retrieve 1st and 2nd wheel? I want to loop through Wheels? I want to get all wheel.Bolts I could not use get/select/[]. Am I missing something? Thanks --M...

EntityFramework 4.0 POCO Proxy Problem

I see a lot of people asking a similar question, but not this exact one. I'm trying to do what I would hope would be relatively simple with POCO proxies. using (var context = new MyObjectContext()) { context.ContextOptions.ProxyCreationEnabled = true; // this does indeed create an instance of a proxy for me... // ...