Edmx POCO files

Nov 7, 2013 at 9:30 AM
I see that for the EDMX file generated in the data project , the simple POCO class Leaves.cs does not exist in the same folder but its referencecing the Leaves.cs in the Entities project . Is that correct ?

How can i achieve the same for a new class edmx i want to create ?
Nov 12, 2013 at 12:27 AM

Yes. Both the Entities and Data project are separated.

You can create the entities manually for the Entities project and then delete any generated code from the EDMX in Data project.

Jan 21, 2014 at 1:39 AM
Edited Jan 21, 2014 at 2:15 AM
How did you get his work?

In my own project, vs2012 with EF 6.0.2, when I delete the generated code as you said, create POCO in Entities project, I always get an error:

In BookDAC.class,

public IEnumerable<Book> SelectAll()
        using (var db = new DbContext(CONNECTION_NAME))
            var q = db.Set<Book>();
            return q.ToList();

where Book is POCO class resides in seperated Entities project ,which is generated by Inertia.

namespace Sample.Entities
/// <summary>
/// Represents a row of Book data.
/// </summary>
public partial class Book
    /// <summary>
    /// Gets or sets a int value for the id column.
    /// </summary>
    public int id { get; set; }

    /// <summary>
    /// Gets or sets a string value for the name column.
    /// </summary>
    public string title { get; set; }

    /// <summary>
    /// Gets or sets a string value for the moniker column.
    /// </summary>
    public string author { get; set; }

System.InvalidOperationException was unhandled by user code
Message=The entity type Book is not part of the model for the current context.
   at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Sample.Data.BookDAC.SelectAll() in d:\Sample\Data\Sample.Data\BookDAC.cs
   at Sample.Test.BookDACTest.TestSelect() in d:\Sample\Tests\Sample.Test\BookDACTest.cs
Jan 24, 2014 at 6:43 AM

In your Sample.Data project, after you have added an ADO.NET Entity Data Model,
  1. delete all the .tt files i.e. SampleModel.Context.tt and SampleModel.tt. Just leave the designer.cs and edmx.diagram.
  2. code your POCOs in Sample.Entities and then make sure you "Add Reference" your Sample.Entities to your Sample.Data.
  3. code your DAC.
Hope it helps.

Dec 9, 2014 at 1:03 AM
Edited Dec 9, 2014 at 1:50 AM
Hi Serena.

I have the same problem, I deleted all .tt files and still get the error "The entity type Encontro is not part of the model for the current context."

My Project.Entities is referenced in Project.Data.


UPDATE: The problem was in foreign key, I deleted the relationship in edmx file for test and worked!
I'll search for more details.

UPDATE 2: The problem was in differences between edmx model and POCO class.
Adding a property for my foreign class solve the problem.

Thanks for your work and samples Serena!
Jan 11, 2015 at 8:00 PM
Other people who have the same problem try to check the connection string .

Connection string sample:
<add name=DATABASEEntities"
connection string=&quot;
data source=(local)\SQLEXPRESS;
initial catalog=PRIVATEDB
;persist security info=True
providerName="System.Data.EntityClient" />
Hope it helps someone.