entity-framework-4

Entity Framework 4: Mapped Stored Procedure on Model with Additional Parameters

We've started using Entity Framework 4 for data access and have come across an issue or perhaps lack of understanding. Our current system is heavily reliant on Stored Procedures, these procedure contain some necessary business logic so we need to continue to use these when doing Select/Insert/Update/Delete. The issue we are having is t...

Building an ObjectContext in EF Code First CTP4

I just upgraded to EF Code First CTP 4 and it looks like the ContextBuilder class was removed. I currently create my ObjectContext like so (in CTP 3): var contextBuilder = new ContextBuilder<ObjectContext>(); var connstr = ConfigurationManager.ConnectionStrings["MyConn"]; var connection = new SqlConnection(connstr.ConnectionString); var...

Ordering Navigation Properties - Entity Framework

Is there a way built into the entity framework or commonly used pattern for ordering lazy loaded navigation properties to ensure no matter how they are accessed they are always in the correct order. I would like to avoid having to write properties or methods on partial classes if possible. Thanks for any help. ...

Entityframework 4: Problem with ForeignKey when removing a child entity from parents collection

New to the EF, I have an issue. OK, so, I have an Entity with a related Table (one-to-many relationship). The entity holds a collection of child objects from the related table. I want to remove an object from the related collection but not from the child table. However, when I call <entity>.myRelatedChildTable.Remove( childEntity ) an...

ASP-MVC2, EF4 and POCO generator error

I'm developing application with ASP.MVC2 & EF4 and some time ago i've interested in POCO and tried to applay it to my project. I've found template to generate code on VisualStudioGallery, but it's not working. Installation was successful, but after choosing template to generate code, i've got error "Object reference not set to an insta...

Entity Framework, Updating

I'm having a great deal of trouble with the Entity Framework (4.0) due to the pattern of 'adding' to a program. (Using ASP.NET MVC) The problem is that it feels like the entire structure of the Entity Framework is designed to 'build everything all at once'. It doesn't seem to lend itself to progressive development, because of all of the...

Database design with table sharing

My application saves posts to database, I have 6 different types of posts and I delibrately NOT joining these post tables with any other tables. Now, they all share some common columns, like, PostID, UserID, Title, Body, PostDate, ViewCount, and many more common columns... And, these 6 types of posts have many of their own unique c...

EntityFramework 4.0: InvalidOperationExecption: Multiplicity constraint violated

Hi, we have recently upgraded our software to .NET 4.0 and EF 4.0 (without self-tracking entities) (former .NET 3.5 SP1). Now a new exception is raised in former working code, which we do not understand. We have an entity called Resident, and another entity called ResidentExtension, which extends the already large Resident entity with ...

Entity Framework 4 selective lazy loading properties

Is it possible to load an entity excluding some properties? One of this entity's properties is expensive to select. I would like to lazy load this property. Is that possible? ...

Change db table name in EF4 (entity framework 4)

Does anyone know how to change the mapped db table for an entity in EF4 (entity framework 4)? Later edit: I think i've found the place where the table names are defined, in the model browser. But their names are readonly, so it's not possible to edit them using the designer. Also, there's no reference (from what i've searched) to the ta...

Entity Framework 4: Problem mapping column to complex type

I have a table with about 30+ columns, so i decided to group them using complex types. When trying to build the assembly, i get the following error: Error 3023: Problem in mapping fragments starting at line 933:Column TableName.ColumnName in table TableName must be mapped: It has no default value and is not nullable. One of my complex t...

Changing the ConnectionString in Entity Framework 4

I'm working on updating an old system, and we're introducing Entity Framework for some new functionality. The system is, however, too large to do the migration in one step, so I would like to do some testing in another database before updating the db schema. I have created an empty model, included a couple of tables from the database, a...

Can't use code generators because of "object reference not set to an instance of..."

What can cause this behaviour? I'm trying to generate code via ADO.NET EntityObject/Poco/SelfTracking Generator and i get only "object reference not set to an instance of an object" error I can add i'm using EF4 with OracleProvider and previously i've generated code with EdmGen2, but right now i'd like to generate POCO classes from exi...

Using MySql with Entity Framework 4 and the Code-First Development CTP

I thought I'd experiment a bit with Scott Guthrie's latest post on code-first dev with Entity Framework 4. Instead of using Sql Server, I'm trying to use MySql. Here are the relevant parts of my web.config (this is an Asp.Net MVC 2 app): <connectionStrings> <add name="NerdDinners" connectionString="Server=localhost; Databas...

MS EF4: How to decipher a self referencing table?

I have a Product table with fields like: public class Product { public int ID {get;set;} ... } and a table that joins Products to other "cross sell" products (like items): public class CrossSell { public int ProductID {get;set;} public int CrossSellID {get;set;} } My intent is, given any product, get a list of cross...

Entity Framework CTP4 and composite keys

Hi I was playing with EntityFramework CTP4 and decided to apply it to one of my current projects. The application uses a SQLServer database and there is one table with a composite key. Say, table "MyEntity" has "Key1" and "Key2" as both foreign keys (individually) and as a composite primary key. I made a configuration class derived fro...

get the id of a new record in SavingChanges event on the entityframework

Hi, Im tring to implement some generic logging in the entityframework 4.0 using the SavingChanges event in the entity context. I want to record details about any create/ update and deleted records including the id of the record being changed (which is always an int identity field). During the update and delete processes I can get the ...

Comparing SQL tables and getting Values using Entity Framework

I have three tables viz: Person(PersonID(INT), Personname(varchar)) , Items(ItemID(INT), Itemname(varchar)) and PersonItemAssoc(PersonItemAssoc(Int), PersonID(INT), ItemID(INT)). PersonItemAssoc is having many to many association for personid and Itemid. I want to get way in which if I pass the itemId, I should get all the Perso...

How to create EF 4.0 entities using an entity name?

I've got a project that is loading ascii data records defined in a Cobol environment. I've got the cobol data structure: things like INVOICE-SECTION, INVOICE-LINE-DETAIL-SECTION etc. with various data fields for each section. There are many sections each of which has a table in my SQL db. I'm using Entity Framework 4.0. I want to be...

Entity Framework 4.0 - Many to Many Relationship

Hello, I have probably stupid question but how Can I create Many-To-Many relationship with create option "Model First". I have read this article http://learnentityframework.com/LearnEntityFramework/tutorials/many-to-many-relationships-in-the-entity-data-model/ but here the autor haven't provided to much description and It is "Database...