entity-framework-4

Anyone succeeded at injecting Interfaces into Entity Framework 4 Entities, using T4?

Hello: POCO sort of leaves me wanting: (how can I say I use DI/IoC, if the Repository is not the only place that is creating the entities?)...hence my desire to lock it down, get rid of the temptation of newing up POCOs or EntityObjects anywhere in the code, and just allowing entity interfaces above the Repository/Factory layer. For a ...

Adding a custom property to my EF4 Model

Let's say I have two tables in SQL that I want to have an EDMX model generated from (for now, going with automagical generation for everything) using POCO T4 templates. Let's say our two tables are Person (ID, FName, LName) and Comment (ID, PersonID, CommentText, CommentDate) with a one-to-many relation between the two (i.e. you can make...

Entity Framework 4 - Code Only - How to set data type property as smalldatetime?

There's a way? var customer = constructor.Entity<Customer>(); customer.Property(c => c.Date).DataType("smalldatetime"); THANKS IN ADVANCE ...

How to query Entities in Entity Framework 4

In VS2008, I think it is EF1.0, this works just fine. string queryString = @"SELECT VALUE USERS FROM ProjectDBEntities.Users AS User INNER JOIN ProjectDBEntities.Favorites AS F ON F.FavUserId = User.UserId WHERE F.UserId = " + 3 + " ORDER BY F.CreateDate DESC "; System.Data.Objects.ObjectQuery<User> use...

A question about entities, roles and interfaces in Entity Framework 4.

Hi, I am an experienced .NET developer but new to EF - so please bear with me. I will use an example of a college application to illustrate my problem. I have these user roles: Lecturer, Student, Administrator. In my code I envisage working with these entities as distinct classes so e.g. a Lecturer teaches a collection of Students. An...

Table-Valued Parameter in Stored Procedure and the Entity Framework 4.0

Hi there, I have a stored procedure in SQL Server 2008 called 'GetPrices' with a Table-Valued Parameter called 'StoreIDs'. This is the type i created for this TVP: CREATE TYPE integer_list_tbltype AS TABLE (n int) I would like to call the SP from my Entity Framework. But when I try to add the Stored Procedure to the EDM, i get the f...

How can I hide a database column in the entity model?

Hi. I'm using the Entity Framework 4 and have a question: I have a password column in my database that I want to manage using custom SQL. So I don't want the model to know anything about it. I've tried deleting the property in the Mapping Details window, but then I got a compilation error: Error 3023: Problem in mapping fragments s...

EF4 performance tips and tricks

I've gotten to that point in one of my projects, and haven't found much information out there. So if you've got some pointers for improving performance in the new Entity Framework 4, please let us know! ...

What's the easiest way to sort an EF4 EntityCollection<T>?

I'd love to add some sorting to an EntityCollection that is bound to an ItemsControl (in xaml). I'd also like to do it as simply as possible. It appears that this is not possible. If I wrap the collection in a "sorted" version of the collection property within the Entity I lose collection change notifications. I can't use a Collectio...

Does Entity Framework 4 not support property automatic lazy loading for model-first entities?

All references that I find for lazy loading say it's possible but they all mention POCOs and that's it. I am using EF4 with the model-first methodology. In my model diagram I have a Project table and a UserObject table, with a 1 to many relationship between them. However, in code, when I have a valid UserObject and I attempt to get th...

Table-per-hierarchy and inheritance implementation issue

I am migrating an old ASP application to a modern .NET version, to cut down on development times we are looking at the .NET 4.0 Entity Framework. However, we seem to have hit a brick wall in our development with this issue. Given is a small part of our database: A table OBJECT which contains a list of cars and their respective propertie...

Entity Framework 4 and persisting foreign key relationships

I am a pretty much a newbie to Entity Framework (specifically version 4) and I am trying to understand an issue I have. I have an ASP.NET MVC2 project I am using with Entity Framework 4 and a Repository class. I have a simple foreign key relationship that I have defined. When I run my MVC project I am able to load the MVC form and updat...

Help with entity frame work error. Error 0194: All artifacts loaded....

This is a c#/asp.net project. The full error message I get is:Error 0194: All artifacts loaded into the item collection must have the same version. Multiple versions were encountered. This project was started as a 3.5 and upgraded to 4.0. When I try to test any of the methods I get the error that I posted in the subject line. I am go...

Best practice for structuring a new large ASP.NET MVC2 plus EF4 VS2010 solution?

Hi, we are building a new web application using Microsoft ASP.NET MVC2 and Entity Framework 4. Although I am sure there is not one right answer to my question, we are struggling to agree a VS2010 solution structure. The application will use SQL Server 2008 with a possible future Azure cloud version. We are using EF4 with T4 POCOs (mode...

Entity Framework 4 omits some associations during model generation

After creating an EF4 model from a SQL Server database I noticed that all the relationships of my Users table were not imported into the model as associations. All the other relationships were imported fine. My Users table has a PK userId which is a char(7) field and it is integrated into several other tables in the database as an FK bu...

CommunicationException in WCF

Hi I have a problem with a WCF Service I've just created. This was working yesterday but for some reason it's just stopped working. One of my WCF methods returns an array of an Entity Framework entity, like this: public BranchContactDetail[] GetClosestBranches(string postcode, int howManyBranches) { GeoLocation geoLoca...

What are some good Repository pattern examples for use with Entity Framework 4.0?

Can anyone refer me to good and complete/semi-complete examples of using EF 4 with the Repository pattern? Thanks! ...

simple Silverlight binding with WCF RIA does not work (I am new bie to WCF RIA)

I am using following markup on Silverlight page: <Grid x:Name="lytEmpForm" Margin="8"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <Colum...

Entity Framework 4 Hiding Underlying Resolver Tables when model is generated from database

When creating an entity framework model from scratch it is possible to specify a Many to Many relationship in the model. e.g Entity1 * ----- * Entity2 When a database is then generated from this, a resolver table is then created automatically between the two entities, this is hidden in the code model, allowing direct access to each of...

Using MVC2 to update an Entity Framework v4 object with foreign keys fails

With the following simple relational database structure: An Order has one or more OrderItems, and each OrderItem has one OrderItemStatus. Entity Framework v4 is used to communicate with the database and entities have been generated from this schema. The Entities connection happens to be called EnumTestEntities in the example. The trim...