Geeks With Blogs
Georgiy Grigorenko
| Home |

Recently I used Entity Framework 4.1 with Code First approach and step on a hidden rake. My application should create an SQL Server CE database file using supplied model classes.

I created some model classes, one of the classes was declared as

namespace MyProject.Models
{
    public class Object
    { 
         public int Id {get; set;}
         public String Name {get; set;}
    }
}


Then, I tried to declare property of DbSet<MyProject.Models.Object> type in my class derived from DbContext:

namespace MyProject.Models
{
    public class MyDbContext: DbContext
    {
        public DbSet<Object> Objects{get; set;}
    }
}

It compiles without any errors, just as expecting. But when I tried to run application, there is no database file generated and application freezes ! I google some time and find the answer - Entity Framework 4.1 cannot work with classes defined in different namespaces (Object is also root class in .NET Framework). So, I renamed my Object class to QObject and database was generated as I expecting. According to MSDN, this feature will be available in future releases of EF.

Posted on Tuesday, August 30, 2011 9:20 PM MVC , Entity Framework , Linq to SQL , ASP.NET | Back to top


Comments on this post: Entity Framework - My Code First Expirience

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Silverlight | Powered by: GeeksWithBlogs.net