entity-framework-4

Unable to use a Stored Procedure with my Entity Framework v4 + POCO's :(

Hi folks, I've got a very simple Entity Framework project with POCO Entities. I've got a single stored procedure which I have imported using the EF Wizard. Kewl. I've then made my own EF Entity which I've then Add Function Import to map the Stored Procedure to my EF Entity. Now ... I'm not sure how to map my EF Entity to a POCO. As su...

Possible to use the Repository Pattern + Stored Procedures ? Should / can they return IQueryable?

Hi folks, I'm a big fan of using the Repository pattern to return IQueryable<T> objects. I then let my services layer determine what does what (eg. filter by XXX, order by YYY, project into ABCD, etc). But I've got some hardcore DB stuff, so I've got it all wrapped up into a Stored Procedure. Works fine. I know EF can execute stored pr...

Serializing POCO Entities

Can I serialize POCO classes? I'm using the C# POCO entity generator. I tried to edit the .tt file which generates the entity classes to add the Serializable attribute. Is it right? ...

Help me give Entity Framework Navigation Properties meaningful names, not User{1,2,3,4,...}

I have inherited a medium sized database that we are trying to use with Entity Framework in a MVC2 rewrite we are working on. We used the existing database to generate the data model (.edmx file) and all was good. Until I realized that I could not use the dot notation access all the fields. appointment.Employee.name // works fine app...

Entity Framework gives me a NullReferenceException

Hey guys, I have created a conceptual entity in my EF model called Task. Then I imported the INSERT, UPDATE, DELETE stored procedures into my model and mapped them to Task. In my client code, I have something like this: myModel.AddToTasks(new Task(...)); myModel.SaveChanges(); However, it gives me a NullReferenceException from Ens...

Basic/Simple Data Access Object (DAO) with Entity Framework 4.0

Hello all, I am trying to put together a simple POC for a n-layer application using EF4 in the data tier. I have looked at numerous examples on the web and it seems to be a common practice to use a DAO or a Repository as the wrapper to an ORM. My understanding that the main difference between the two is that a Repository is more generi...

Using CreateSourceQuery in CTP4 Code First

I'm guessing this is impossible, but I'll throw it out there anyway. Is it possible to use CreateSourceQuery when programming with the EF4 CodeFirst API, in CTP4? I'd like to eagerly load properties attached to a collection of properties, like this: var sourceQuery = this.CurrentInvoice.PropertyInvoices.CreateSourceQuery(); sourceQuer...

Is there any API that allow to track object changes in entity framework.

Hello everyone! Does anybody know if there are any solution like 'Hibernate History API' for entity framework. If no, may be there are some history tracking practise/patterns applied to EF. I'm newbie to EF so far. Any refs are welcome. Thanks in advance. ...

How to access to sub properties in entity framework CTP4?

I am pretty new to entity framework, but given a simple object like this: public class Country { public string Name { get; set; } [Key] public string Code { get; set; } public bool IsPostalCodeRequired { get; set; } public ICollection<Province> Provinces { get; set; } } returned by a DbContext, the Provinces pro...

Self referencing foreign key - GUID - Entity framework 4 insert problems

I have successfully used EF4 to insert rows automatically with a server generated GUID: http://leedumond.com/blog/using-a-guid-as-an-entitykey-in-entity-framework-4/ Now how does one perform this task if there exists a RowID (guid) and ParentRowID (guid) with a primary-foreign key constraint between the two? What would I set .ParentRo...

EF4 Self Tracking Entities: OptimisticConcurrencyException after MarkAsDeleted

Hello I have some logic whereby a graph of POCO entities need to be cloned and to do this I have created partial classes for each T4 generated self tracked entity and implemented ICloneable on each. Each entity can clone itself and iterates through all of its children in navigation properites and calls Clone() on each child entity, then...

EF4 STE's and MVC2 - ChangeTracker not POSTing

I'm trying to set up an MVC2 app with Entity Framework Self-Tracking-Entities. My view is a strongly-typed view of the entity type generated by the STE T4 template. Here's my GET: public ActionResult Edit(int id) { var ri = new App1Service.App1Client().GetMyObj(id); var changeTracking = ri.ChangeTracker.ChangeT...

Entity framework 4 - Base entity mapping 2 tables as base class for 2 derived entities possible?

I have the following scenario that is causing me problems around the mapping fragments referring to same Id columns. This is what im trying to achieve not sure its even possible! Essentially I want to have a common way of accessing content, and as needed a specialisation of blog and article. I have the Contents entity working with the...

How do I update a nested property with Entity Framework

I've got a ToDo class which has properties for Staff and Priority. If a user updates a ToDo item, changes the TaskName and maybe sets a new Priority how do I update the Priority property - public class ToDo : BaseEntity { public DateTime? DueDate { get; set; } public String Notes { get; set; } public virtual Priority Priori...

How to map foreign keys using entity framework CTP4 POCO annotations with an existing database

I have an existing DB with a very simple one-way foreign key relationship between two tables. I need to create classes with mappings that will work with the existing DB. CREATE TABLE OfflinePackage ( PackageID int, Name nvarchar(100) ... CREATE TABLE OfflinePackageDocument ( PackageDocumentID int, PackageI...

Update EF 4 Feature CTP 4 Detached POCO

I am trying to update a detached POCO w/ EF 4 CTP 4. My domain class looks like this: public class User { public int Id { get; set; } [Required, DisplayName("First Name")] public string FirstName { get; set; } [Required, DisplayName("Last Name")] public string LastName { get; set; } [ConcurrencyCheckAttribute, Timestamp]...

Entity framework with integer primary key but not auto-int does not pass to database

Here's the table and code public class Person { [Key] public int ID {get;set;} public string Name {get;set;} } var owner = new Person() { ID = 1, Name = "Owner" }; db.People.Add(Person); db.SaveChanges(); The SaveChanges method does not add ID to the sql so I end up with the following sql query exec sp_executesql N'insert [d...

Entity Framework query

I ran across this code in one of our Entity Framework applications. I know there has to be a better (more efficient) way than the three queries this code executes. Although, I can't quite get the syntax right. (I am still learing Entity Framework myself..) There are two tables involved. This is a simple parent/child relationship. Ther...

How to map an Entity framework model to a table name dynamically

Using a code-first approach I'd like to map a single model to multiple table names dynamically. Currently I can do something like modelBuilder.Entity(Of Person)().MapSingleType().ToTable("Managers") but as the OnModelCreating method is only called once I can't map it to other table names on the fly. In our current LinqToSql version we'r...

EF4 many-to-many navigation property is empty

Using the model-first approach, I made 2 entities: Project and User. A project has multiple Users (involved in the project), and a User has (access to) multiple Projects, so following along with the Tekpub video, I made the many-to-many navigation property using the primary keys of the two entities. I made some test data, and the data ...