Share via


EF Feature CTP5 Released!

 


The information in this post is out of date.

Visit msdn.com/data/ef for the latest information on current and past releases of EF.


 

The latest Entity Framework Feature Community Technology Preview (CTP5) is now available for download. This CTP includes updates to the Code First feature and the simplified API surface (DbContext).

Getting Started

We’ve created a couple of posts to get you started with CTP5, we’ll also be providing more detailed posts that dive down into interesting areas in the coming weeks.

Support

CTP5 is a preview of features that will be available in future releases and is designed to allow you to provide feedback on the design of these features. CTP5 is not intended or licensed for use in production. If you need assistance with CTP5 we have an Entity Framework Pre-Release Forum.

Road Map

CTP5 will be our final preview of Code First and the simplified API surface (DbContext) before we offer a full supported production ready release in Q1 of 2011.

Known Issues

CTP5 includes some significant internal refactoring in preparation for some features we intend to support in the future, we are still in the process of stabilizing the quality after this refactoring. We decided to release before we finished this stabilization to get CTP5 in your hands as soon as possible and give ample time to incorporate feedback before we RTM.

In particular there are some specific known issues in CTP5;

  • Table & Column Mapping in the Fluent API
    We have done some work to make the mapping of classes/properties to tables/columns simpler and more intuitive in CTP5. We are still working to improve the quality of this new work, particularly around the mapping of inheritance hierarchies.
  • Pluggable Conventions
    CTP5 includes a very early preview of this feature that is not complete and has not been extensively tested.
  • The new Validation feature is currently only supported when using Code First

 

What’s Changed?

There are a number of changes to existing features since CTP4, so you may be wondering where to find things:

  • New Assembly Name
    Our assembly name has changed to EntityFramework.dll
  • Better Code First to Existing Database Support
    CTP5 removes the need to switch off Database Initializers when working with existing databases with Code First. If you map to an existing database that Code First did not create then it will just ‘trust you’
  • DbContext.ObjectContext has moved
    Rather than being a protected member we have made the underlying ObjectContext  available via an explicitly implemented interface, this allows external components to make use of the underlying context. Getting the context now looks like; ((IObjectContextAdapter)myContext).ObjectContext
  • Excluding EdmMetadata Table
    If Code First is generating your database and you wish to exclude the EdmMetadata table, this is now done by removing a convention (note that you do no longer need to do this when mapping to an existing database).
 public class MyContext : DbContext
{
    ...

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<IncludeMetadataConvention>();
    }
}
  • Class Changes
CTP4 Name CTP5 Name
Database System.Data.Entity.Database.DbDatabase
RecreateDatabaseIfModelChanges System.Data.Entity.Database.DropCreateDatabaseIfModelChanges
AlwaysRecreateDatabase System.Data.Entity.Database.DropCreateDatabaseAlways
CreateDatabaseIfNotExists System.Data.Entity.Database.CreateDatabaseIfNotExists
SqlConnectionFactory System.Data.Entity.Database.SqlConnectionFactory
SqlCeConnectionFactory System.Data.Entity.Database.SqlCeConnectionFactory

 

What’s New?

New additions since CTP4 include;

DbContext
  • T4 Templates for using DbContext/DbSet with Model First & Database First

  • Validation of objects on save

    Validation is based on the use of Data Annotations and currently only supported in Code First

  • Change Tracker API

    Allows you to access information and operations applicable to objects that are tracked by a DbContext

    • Original, Current & Store Values
    • State (i.e. Added, Unchanged, Modified, Deleted)
    • Explicit Load (i.e. load the contents of a navigation property from the database)
  • DbSet.Local exposes an ObservableCollection representing the local contents of the DbSet

    This is particularly useful when performing databinding in WPF or WinForms

  • Support for No-Tracking Queries via the AsNoTracking extension method on IQueryable<T>

  • DbContext Configuration 
    Allows the following options to be configured for a DbContext instance;

    (Note: All of these are On by default)

    • Lazy Loading
    • Validate On Save
    • Auto Detect Changes
  • Raw SQL Query/Command

    Allows raw SQL queries and commands to be executed via the SqlQuery & SqlCommand methods on DbContext.Database. The results can optionally be materialized into object instances that are tracked by the DbContext via the SqlQuery method on DbSet.

  • Improved concurrency conflict resolution

    CTP5 provides better exception messages that allow access to the affected object instance and the ability to resolve the conflict using current, original and database values

Code First
  • Full data annotation support

    The full list of data annotations supported in CTP5 is;

    • KeyAttribute

    • StringLengthAttribute

    • MaxLengthAttribute

    • ConcurrencyCheckAttribute

    • RequiredAttribute

    • TimestampAttribute

    • ComplexTypeAttribute

    • ColumnAttribute

      Placed on a property to specify the column name, ordinal & data type

    • TableAttribute

      Placed on a class to specify the table name and schema

    • InversePropertyAttribute

      Placed on a navigation property to specify the property that represents the other end of a relationship

    • ForeignKeyAttribute

      Placed on a navigation property to specify the property that represents the foreign key of the relationship

    • DatabaseGeneratedAttribute

      Placed on a property to specify how the database generates a value for the property (Identity, Computed or None)

    • NotMappedAttribute

      Placed on a property or class to exclude it from the database

  • Fluent API Improvements

    • Simplified table and column mapping
    • Ability to ignore classes & properties
  • Pluggable Conventions

    Based on the large amount of feedback requesting this feature we have included an early preview in CTP5. We still have some work to do on this feature but we wanted to give you the chance to provide feedback before we RTM. We’ll provide more details on this feature in the coming weeks.

 

Please keep the feedback coming!

ADO.NET Entity Framework Team

Comments

  • Anonymous
    December 06, 2010
    I have a question regarding this one T4 Templates for using DbContext/DbSet with Model First & Database First I will be starting a new project and would like to use the DbContext t4 template for Database First Approach. Would this t4 template be the default template Ef would use moving forward in the next version of Ef or will the default code generation still be EntityObject? Zeeshan

  • Anonymous
    December 07, 2010
    DbDatabase is a little bit confusing name.

  • Anonymous
    December 07, 2010
    I like default naming convention for FK table columns which is now ParentTableId, not ParentTable_Id. It is much cleaner. Waiting for blog posts about Pluggable Conventions.

  • Anonymous
    December 07, 2010
    I have been building my code first (since CPT3) using ObjectContext and returning IObjectSet. Is now a deprecated way of doing things? Seems the focus is on DbContext...?

  • Anonymous
    December 07, 2010
    Will be a NuGet package made for this CTP, like 'EFCTP4'? Or is it 'EFCodeFirst' package? (Sorry, I'm a little bit confusing about the later one as there is no additional info nor in its description, neither on the web).

  • Anonymous
    December 07, 2010
    Regarding my previous comment about NuGet. Licence text for 'EFCodeFirst' package says that this is 'MICROSOFT ADO.NET ENTITY FRAMEWORK FEATURE COMMUNITY TECHNOLOGY PREVIEW 5'. It seems that this is it, regardless of version number 0.8.

  • Anonymous
    December 07, 2010
    @Zeeshan Our hope is to make the DbContext template the default moving forward. Keep in mind that there are still some features it does not support in the CTP (such as function imports).

  • Anonymous
    December 07, 2010
    The NuGet package EFCodeFirst is CTP5.

  • Anonymous
    December 07, 2010
    @ibmec The NuGet package for CTP5 is EFCodeFirst. This is the name going forward, and has a NuGet package version of 0.8 so this version can be upgrade by the RTM release when that becomes available.

  • Anonymous
    December 07, 2010
    I need more docs. ModelBuilder no longer has CreateModel() ????? My Code is getting ugly: //_database = builder.CreateModel(connection); LEG 1 CPT 3 //var ctx = dbModel.CreateObjectContext<ObjectContext>(_connectionString); LEG 1 CPT 3 //var modelBuilder = builder.CreateModel(); LEG 2 CPT 4 //_database = modelBuilder.CreateObjectContext<Database>(connection); LEG 2 CPT 4

  • Anonymous
    December 07, 2010
    @Paul, @ObjCtx vs DbCtx Yes, the pattern for explicitly using ModelBuilder with an ObjectContext has changed between CTP4 and CTP5. Our focus is on the experience using the DbContext class, but it is still possible to use ModelBuilder with an ObjectContext: ModelBuilder m = new ModelBuilder(); DbDatabaseMapping dbm = m.Build(connection); DbModel model = new DbModel(dbm); model.CreateObjectContext<ObjectContext>(connection); There are several new classes and likely the DbDatabaseMapping and DbModel classes will get new names before RTM. Our ultimate intention is to create one mutable and one "compiled/fast/cached" version of the model that the ModelBuilder creates which is why you see those classes (although DbDatabaseMapping's mutability is not public yet). It's good feedback that this is making your code look messy so we'll review this prior to RTM.

  • Anonymous
    December 07, 2010
    Is there any new tooling or updates for the EmptyModel option...

  • Anonymous
    December 07, 2010
    This stuff is absolutely fantastic!! The steady progression from the first CTP to this has continually added functionality to make this the option I choose first when starting a new project. Way to go guys!!

  • Anonymous
    December 07, 2010
    @Jeff Thanks for the reply. My main reason for using ObjectContext and returning IObjectSet is for testability and because in my Repository base I can use ObjectSet<T>() for Add, Delete and GetById methods so they do not have to be defined on each Repository. I guess I will have to look at a different way of building a Repository/UoW with DbContext and IDbSet<T>. Thanks again for the reply.

  • Anonymous
    December 07, 2010
    Have you fixed the issue with TPT inheritance will generate thousands of lines of sql when trying to get an instance of the base type (which should generate 'SELECT * FROM BaseType')? To get around this in EF4 we've had to create a view which is a summary of the base type, however this does not have navigation properties so is very limited. Many thanks, Adam

  • Anonymous
    December 07, 2010
    Do you plan to include schema migrations for versioning?

  • Anonymous
    December 07, 2010
    @Hector There's a lot of great new stuff in CTP5 for the "empty model" scenario. Consider this one: class Program    {        static void Main(string[] args)        {            DbContext db = new DbContext("Northwind");            foreach (var c in db.Database.SqlQuery<CustomerInfo>("select c.contactname, " +                                                                 "(select COUNT(*)                                                                    from orders                                                                    where CustomerID = c.CustomerID) as ordercount " +                                                                 "from Customers as c"))            {                Console.WriteLine(c.ContactName + ": " + c.OrderCount);            }        }    } In this scenario you still have no connection string (just refer to the database name if you are targeting SQL Express), and you can use methods like "SqlQuery" on the Database property of the DbContext.

  • Anonymous
    December 07, 2010
    The comment has been removed

  • Anonymous
    December 07, 2010
    @Roberto Schema (and data) migration is part of our longer term plan for Code First workflows. It is not part of CTP5 and will not be part of the initial RTM release, but we are working on a schedule that makes this land shortly after that release. If you have specific migration scenarios you think are important to target, please let us know!!

  • Anonymous
    December 07, 2010
    1.DbDatabase which means "Database Database???" or DbSqlQuery not a good name and I'm agree with  Alexey Veselovskiy  which is a confusing name. 2.Microsoft.Data.Entity.CTP.dll was better assembly name than the general "entityframework.dll" which we all know it's not "entity framework"

  • Anonymous
    December 07, 2010
    What are the plans for being able to use this with WCF RIA Services? Currently to make a domain service, you derive from LinqToEntitiesDomainService<T> Would be nice to be able to use code-first here!

  • Anonymous
    December 07, 2010
    The comment has been removed

  • Anonymous
    December 07, 2010
    @divega "The argument was that the benefit of having a standard prefix for the predictability and discoverability of the API was more important than the harm of having a few a names that were a little redundant or obtuse of you want to pay attention to the original meaning of “Db”." 100% agree!

  • Anonymous
    December 07, 2010
    @divega and Programmerhead Maybe name it Db?

  • Anonymous
    December 07, 2010
    Since there is no mention, I take it there is still no support for enums?

  • Anonymous
    December 07, 2010
    Vote +1 for changing assembly name back.  Making it look like a namespace is a good thing:

  1. Keeps things organized.  The Microsoft.Data prefix tells you it's from Microsoft and that it is data-related.
  2. Prevents naming collisions.
  3. Developers can create similarly named assemblies that, say, extend your assembly, and you know just by looking at the name that they probably belong together (e.g. Josh.Data.EntityFramework).
  • Anonymous
    December 07, 2010
    I thought the naming in CTP4 was better. Anyway, Take a look to the following code:    public class Context : DbContext    {        public DbSet<Bank> Banks { get; set; }        public DbSet<Branch> Branches { get; set; }    }    public class Bank    {        [Key]        public string Name { get; set; }        public string Location { get; set; }        public List<Branch> Branches { get; set; }    }    public class Branch    {        [Key]        public string Code { get; set; }        public string Name { get; set; }        public Bank Bank { get; set; }    } After running the following statements:            Context c = new Context();            Bank b = new Bank() { Name = "Mellat", Location = "Tehran" };            Branch br1 = new Branch() { Code = "01", Name = "Zartosht", Bank = b };            Branch br2 = new Branch() { Code = "02", Name = "Fatemi", Bank = b };            c.Banks.Add(b);            c.Branches.Add(br1);            c.Branches.Add(br2);            c.SaveChanges(); I saw the strange behavior of the database creation. The "Branches" Table does have "Name" column but does not corresponds to "Name" property of the  "Branch" class. It corresponds to "Name" property of the  "Bank" class and the data along with "Name" property of Branch is lost.

  • Anonymous
    December 07, 2010
    Is it or will it be possible for one to also validate on save using non-DataAnnotations attributes?  For example, Castle Validation.  Is this what the "Pluggable Conventions" concept would provide?

  • Anonymous
    December 07, 2010
    The comment has been removed

  • Anonymous
    December 07, 2010
    A big +1 for Pluggable Conventions! :)  I'm anxiously awaiting the post.

  • Anonymous
    December 07, 2010
    Is there any chance the next will release allowing me to use interfaces for the mapping configurations? See my forum post: social.msdn.microsoft.com/.../ebe48aa3-14df-475e-bc5e-80734f85ace4

  • Anonymous
    December 08, 2010
    Is it possible to use Code-First against Sql Azure?

  • Anonymous
    December 08, 2010
    What about property changed validation?, i really need that (or is there a better way?) not just on save changes. How to implement IDataErroInfo? Can you add more validation samples?

  • Anonymous
    December 08, 2010
    @Sean Code First is a programming pattern layer on top of Entity Framework 4.0 (in .NET 4.0). Changes to things like the type system to add enums or changes to query behaviors can only be made when we upgrade the full Entity Framework. This means that the Code First CTPs and RTM early next year will not include enums or any new data types.

  • Anonymous
    December 08, 2010
    The comment has been removed

  • Anonymous
    December 08, 2010
    @Joshua DbDatabase is not a very popular name. We will revist this. Any suggestions would be helpful.

  • Anonymous
    December 08, 2010
    @Markus Yes, Code First does work with SQL Azure. Just use a SQL Azure connection string.

  • Anonymous
    December 08, 2010
    @Joshua In terms of validating using non-ValidationAttributes, you have two options:

  1. Use the IValidatableObject interface on your entities.
  2. Override the protected override DbEntityValidationResult ValidateEntity(DbEntityEntry entityEntry, IDictionary<object, object> items) method on your DbContext and do your own validation there. Unfortunately the pluggable conventions won't help you add a convention to change what is validated yet, but that's a good idea that we will track.
  • Anonymous
    December 08, 2010
    What about dynamic object model? treating an entity as a collection of properties Customer would like to add new properties (columns) Can it be done?

  • Anonymous
    December 09, 2010
    I am using  WCF Data Services and EF CTP5. When I try to access my entities through ADO.NET Data Services a get the error "Internal Server Error. The type 'System.Data.Entity.DynamicProxies......' is not a complex type or an entity type". In my Data service class I override the CreateDataSource method like this:   protected override Models.EntitiesContext CreateDataSource()        {            Models.EntitiesContext dc = new Models.EntitiesContext();            dc.Configuration.LazyLoadingEnabled = false;            return dc;        } But the problem persists. Thanks, Luciano.

  • Anonymous
    December 09, 2010
    ColumnAttribute does not seem to work for the following code [Column(Name="CreatedById")] public virtual User CreatedBy { get; set; } User is an entity, the created field is UserId

  • Anonymous
    December 09, 2010
    @Anthony The ColumnAttribute doesn't work on navigation properties, but I really like the idea this suggests of dictating what the foreign key column name should be. We'll keep that in mind for the RTM release. In the mean time, if you want to specify the foreign key column name, you have to dro pdown to the fluent API: modelBuilder.Entity<Bank>()    .HasMany(b => b.Branches)    .WithRequired(br => br.Bank)    .IsIndependent()    .Map(mc => mc.MapKey(b => b.Id, "BankId"));

  • Anonymous
    December 09, 2010
    The comment has been removed

  • Anonymous
    December 09, 2010
    @Tom This is not something you can do today. Both entities that are property bags and mappings that allow you to dynamically expand your entities are on our futures list.

  • Anonymous
    December 09, 2010
    The comment has been removed

  • Anonymous
    December 09, 2010
    What will happen with generated non-virtual POCO properties regarding proxy ? I need to know if I have to modify the .tt file for implementing INotifyPropertyChanged. Thank you !

  • Anonymous
    December 09, 2010
    public class ProductContext : DbContext {    public ProductContext()        : base("MyProductDatabase")    { } } This snippet of code worked with EF CTP4 but does not work with EF CTP5. It looks like overloaded constructor with connectionString was removed. Why?

  • Anonymous
    December 09, 2010
    Jeff, dc.Configuration.ProxyCreationEnabled used to work in CTP4  that property is buried in Configuration._internalContext.ObjectContext.ContextOptions.ProxyCreationEnabled in CTP5. I had to use reflection to change the value of that property.

  • Anonymous
    December 09, 2010
    Hello,i need  Default Attribute  Binding Attribute Description Attribute . that will Perfect

  • Anonymous
    December 10, 2010
    The Annotations like TableAttribute, ForeignKeyAttribute, should probably not be in System.ComponentModel.DataAnnotations namespace.   If another ORM or linq framework wanted to make use of the validation attributes and had attributes with the same name, it would make using just the data validation painful. On the flipside, if an ORM would like to use the same attributes, they would have to currently reference the code first lib, so a better route would probably be to keep those in a separate namespace till they can be ported into the System.ComponentModel.DataAnnotations.dll in a future .net release.

  • Anonymous
    December 10, 2010
    If someone is interested in Pluggable Conventions I wrote a post about this: pernontacere.blogspot.com/.../entity-framework-ctp5-e-pluggable.html

  • Anonymous
    December 11, 2010
    @Luciano, I had the same problem and found it the right way (without reflection) var contextOptions = ((IObjectContextAdapter)this).ObjectContext.ContextOptions; contextOptions.ProxyCreationEnabled = false; contextOptions.LazyLoadingEnabled = false;

  • Anonymous
    December 11, 2010
    However I see that CTP5 code first + WCF Data Services mix is actually very buggy If you try to do any $select=SomeProperty it crashes ugly with this error: { -error: { code: "" -message: { lang: "en-GB" value: "Not Implemented" } -innererror: { message: "Unable to create a constant value of type 'System.Data.Services.Internal.ProjectedWrapper2'. Only primitive types ('such as Int32, String, and Guid') are supported in this context." type: "System.NotSupportedException" stacktrace: " at System.Data.Objects.ELinq.ExpressionConverter.ConstantTranslator.TypedTranslate(ExpressionConverter parent, ConstantExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) at System.Data.Objects.ELinq.ExpressionConverter.ConditionalTranslator.TypedTranslate(ExpressionConverter parent, ConditionalExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input) at System.Data.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression lambda, DbExpression input, DbExpressionBinding& binding) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter parent, MethodCallExpression call) at System.Data.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq) at System.Data.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq) at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.IEnumerable.GetEnumerator() at System.Data.Services.Internal.ProjectedWrapper.EnumerableWrapper.GetEnumerator() at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)" } } } Any ideas??

  • Anonymous
    December 11, 2010
    Also if I use $expand=SomeNavigationProperty -> It always returns that navigation property null

  • Anonymous
    December 11, 2010
    @Jeff I've noticed your advice but the default behavior of foriegn key column generation should produce a column name "Bank_Name" in foriegn table intead of "Name" to avoid the problem. If I add a property named "Code" in "Bank" entity and mark it as the key property of the entity, it  produces a column name "Bank_Code" as foreign key. It should do so for "Name" property as the key and name it "Bank_Name".

  • Anonymous
    December 11, 2010
    [QueryInterceptor("User")] public Expression<Func<User, bool>> Filter_User() { var db = this.CurrentDataSource; return u=u.IsApproved && db.ProjectWorkers.Any(u.UserId); } This crashes and saying "The ObjectContext instance has been disposed and can no longer be used for operations that require a connection." C'mon, this is a huge bug! Can anyone give me a good example of how to do some real filtering on the query interceptors? And btw, this used to work with LINQ-TO-SQL and EF .NET 4.0!

  • Anonymous
    December 11, 2010
    The comment has been removed

  • Anonymous
    December 11, 2010
    @Luciano We'll be adding ProxyCreationEnabled to the DbContext.Configuration property. In CTP5, it is a bit burried, but you do not need to use reflection to set this, you can do it here: ((IObjectContextAdapter)ctx).ObjectContext    .ContextOptions    .ProxyCreationEnabled = false;

  • Anonymous
    December 11, 2010
    @Bert That ctor is still there in CTP5: public MyContext() : base("MyConnectionString-or-db-name") { }

  • Anonymous
    December 11, 2010
    CTP5 had a considerable number of API changes from CTP4. As we move towards our RTM release in Q1 of 2011, there are likely only a few things that will change based on feedback from this CTP, but programming patterns will remain the same.

  • Anonymous
    December 11, 2010
    @Dan CTP5 had a considerable number of API changes from CTP4. As we move towards our RTM release in Q1 of 2011, there are likely only a few things that will change based on feedback from this CTP, but programming patterns will remain the same.

  • Anonymous
    December 12, 2010
    Is there a way you could do away with the pluralization of table names by default (e.g. having a table named People rather than Person, or even Departments instead of Department)? Personally, I find it annoying. I've always used names that matched exactly for my class names and table names (i.e. when I've used NHibernate before EF existed). This is different from commonly refererred to example databases such as Northwind, but, the same as other more modern examples such as AdventureWorks. i.e. The table names in AdventureWorks are all singular names. Also, using singular names makes link tables for many to manys looks more consistent as well. For example, say I have a Person table and a Department table and it's a many to many relationship. I think it looks best when it's something like this. Person Department PersonDepartment I didn't like the naming conventions that EF 4 RTM used with the underscores. Note, use of underscores goes against .NET coding/style conventions. If it isn't the default, it would be great if it were as simple as calling a single method to turn off pluralization of table names for those of us who don't like it.

  • Anonymous
    December 12, 2010
    Does anyone know if there is an equivalent to NHibernate Interceptors in EF, or EF Code First? I used to use an interceptor in NHibernate that would call a method before an object was persisted which allowed me to set properties in the object such as LastWriteUserName and LastWriteTime which contain the current user and time. On a slightly related note, does anyone know if it's possible to do something like the following with EF Code First? I don't want to use TPT or TPH for this. I just want it to add a few extra columns to the child classes from the parent. class Person : AuditObject { string Name ... } class Department : AuditObject { ... } class AuditObject { DateTime? LastWriteTime .. string LastWriteUserName ... } I was also thinking it would be nice if there were a SavedChanges event in addition to the SavingChanges event that could maybe be used for something like an audit log. i.e. it would let you write out log entries documenting which objects were successfully saved to the database.

  • Anonymous
    December 12, 2010
    On code CafelDataInitializer : System.Data.Entity.Database.DropCreateDatabaseIfModelChanges<CafelDataContext> { protected override void Seed(CafelDataContext context) var collections = new List<Collection>            {                new Collection{                     Fabric= fabrics[0]                    ,FabricID = fabrics[0].FabricID                    ,Title="First Collection"                    ,CollectionImage= String.Format(collectionPlaceHolder, "first Collection")                    ,CollectionDate = DateTime.Now                    ,Description=lore                }... collections.ForEach(c => context.Collections.Add(c));            context.SaveChanges(); got error Unable to cast object of type 'System.DateTime' to type 'System.Array'.  Worked in CTP 4 What is Wrong ????

  • Anonymous
    December 13, 2010
    Currently all the properties of an entity are mapped to columns on a table unless you specify to ignore it using the fluent API or attribute. Is there a way to specify a default value for all the properties to Ignore and then map all the necessary properties. In my scenario I want to codgen an entity and then extend it using partial class o inheritance but I don´t want to force the consumer of the class to add the ignore attribute to all the properties that he may add. Luciano.

  • Anonymous
    December 13, 2010
    @dotnetwise.com The issue with Code First and Data Services is due to the fact that Data Services does not yet support a DbContext directly. In the meantime, you can work around this by obtaining an ObjectContext from the DbContext. First, type your DataService with ObjectContext: e.g., public class MyService : DataService<ObjectContext> Then, override the CreateDataSource method to create and return the Object Context:, e.g.,        protected override ObjectContext CreateDataSource()        {            MyDbContext dbContext = new MyDbContext();            return ((IObjectContextAdapter)dbContext).ObjectContext;        }

  • Anonymous
    December 13, 2010
    The comment has been removed

  • Anonymous
    December 14, 2010
    The comment has been removed

  • Anonymous
    December 15, 2010
    I created a little function in CPT4 that was able to discover and load StructuralTypeConfiguration classes in the DbContext.OnModelCreating(modelBuilder) method. I notice in the CPT5 release that the ModelBuilder.Configurations.Add() methods have changed signatures and no longer allow adding of StructuralTypeConfiguration classes. Are there alternatives available to help in dynamic loading of ComplexTypeConfiguration and EntityTypeConfiguration classes? Thx

  • Anonymous
    December 15, 2010
    data.uservoice.com/.../72025-ado-net-entity-framework-ef-feature-suggestions Do anybody in EF team manage this? If there will be any reaction there (some suggestion in completed list or at least in accepted)?

  • Anonymous
    December 16, 2010
    I am having problem wirh Security Exception: social.msdn.microsoft.com/.../316a043a-98b0-4b91-b68f-723d588dad53

  • Anonymous
    December 18, 2010
    Now that CTP5 has several data annotation attributes (e.g. KeyAttribute, StringLengthAttribute, etc.), is there a way to specify them outside of the model class they are intended to decorate? For instance, I'd like to be able to do something like the following in the OnModelCreating override: modelBuilder.Decorate<MyModel>(m => m.MyProperty).With(() => new StringLengthAttribute(50)); This way, my model classes can live in a library project that doesn't need to reference the System.ComponentModel.DataAnnotations DLL. More importantly, if I have only the DLL containing the model classes and not the source (perhaps because it came from a different team in my organization), I cannot conveniently add such annotations.

  • Anonymous
    December 22, 2010
    The comment has been removed

  • Anonymous
    December 27, 2010
    gkklbhh

  • Anonymous
    December 27, 2010
    How about support for POC generics? I would really appreciate to be able to store my Configuration<T> entities since T could be any data type and there will be a lot of data types.

  • Anonymous
    December 28, 2010
    The comment has been removed

  • Anonymous
    January 04, 2011
    Seth, I was not able to repro the issue with CTP5.  Could you provide more details on how your context is setup and how A, B, and  C are defined?  It might be helpful to post a question on the ADO.NET Entity Framework and LINQ to Entities (Pre-Release) MSDN forum since it is easier to create a thread there that we can use to drill down into the issue.  The forum address is: social.msdn.microsoft.com/.../threads. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Seth I was not able to repro the issue with CTP5.  Could you provide more details on how your context is setup and how A, B, and  C are defined?  It might be helpful to post a question on the ADO.NET Entity Framework and LINQ to Entities (Pre-Release) MSDN forum since it is easier to create a thread there that we can use to drill down into the issue.  The forum address is: social.msdn.microsoft.com/.../threads. Thanks, Arthur

  • Anonymous
    January 04, 2011
    The pluralizing of table names can be turned off by removing the convention that performs this service.  For example:        protected override void OnModelCreating(ModelBuilder modelBuilder)        {            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();        } The convention is in the System.Data.Entity.ModelConfiguration.Conventions.Edm.Db namespace. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Jon M EF doesn’t have anything quite like the Nhibernate interceptors as I understand them—however, I don’t know too much about them.  You can override SaveChange in your context and then use the change tracking API on DbContext to iterate over the tracked entities and set properties, etc.  This might allow you to do something similar, but probably not quite so elegantly. You can use a base class in your model and by default Code First will not bring the class into your model but will instead map properties from it into each of the derived classes and therefore create the extra columns that you are looking for.  Note however, that if you define relationships between the base class and other entities or explicitly map the base class then it will be brought into your model and mapped using TPH by default. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Dima L This exception is thrown by the new validation code if you have a MinLengthAttribute on a DateTime property.  MinLength is currently not supported on DateTime properties—we are looking into whether or not we can make the exception easier to understand. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Luciano There isn’t a way to do this now but we have heard this feedback and are looking into what we can do to support this scenario. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Elmar, I think you will have to handle ComplexTypeConfiguration and EntityTypeConfiguration separately for now.  We will look into this case to see if we can make it easier. Thanks, Arthur

  • Anonymous
    January 04, 2011
    @Alexander Kot, Yes the EF team pay close attention to the suggestions and voting.  We use this information (together with other factors) in helping to prioritize where we should spend our resources for upcoming releases. Thanks, Arthuir

  • Anonymous
    January 04, 2011
    @Chris You can use the Code First fluent API to set facets of the model, such as the max length for a string property, without using data annotations.  The validation feature currently only validates against data annotations, but we are looking into making it validate against facets set with the fluent API as well.  Other than validation it has the same effect on the model as using the data annotations does. It would be useful to know how you would like to use the data annotations if they were put into the model in this way? Thanks, Arthur

  • Anonymous
    January 04, 2011
    @SvanSr Mapping to generic types is currently not supported by the core EF libraries on which Code First is built.  It is something that we would like to add in a future release of EF but it will not make it into the first release of Code First/DbContext.  Note that you can have an unmapped generic base type for your entities. Thanks, Arthur

  • Anonymous
    January 04, 2011
    How can I generate DDL for creating or updateing the database objects of my code first model? The database is ORACLE, the provider is Devart dotConnect. Also, I would like to know, the database key can be automatically created, when I insert a new entity. I am using the Fluent API to define the model like this:            modelBuilder.Entity<TestEntity3>()                .Property(entity => entity.Id)                .HasColumnName("ID")                .HasDatabaseGenerationOption(DatabaseGenerationOption.Identity); Best Regards, Gerhard

  • Anonymous
    January 05, 2011
    Hi ADO.Net Team When will(if ever) the EntityPropertyMapping attribute be supported?  I would like to be able to customize the odata output when you put the WCF Data Service on top of this.  Maybe I am missing something but it does not appear to work(getting a null reference exception) From MSDN: msdn.microsoft.com/.../system.data.services.common.entitypropertymappingattribute.aspx Thanks, Dan

  • Anonymous
    January 05, 2011
    Is there any feedback if you intend to add Jarek Kowalski's Entity Framework caching provider into SP1 with caching support for stored procedures ? We're currently evaluating whether to go with winforms or WPF, WPF more likely. The biggest question mark is entity framework and it's lack of caching and especially stored procedure caching. Our LOB system uses a lot of stored procs and they aren't going to be re-written in a hurry so we need to data access layer with good stored proc support, LINQ would have been the way to go but MS suddenly dropped it/rolled it into EF. We'd rather use a MS data access layer for obvious reasons but EF gives us a lot of question marks and we need to decide soon.

  • Anonymous
    January 06, 2011
    Just realized that the new DBContext doesn't support Compiled Queries... This has to make the final release.  This is the simplest way to squeeze out decent performance from EF and you took it away!  What is the status of this?

  • Anonymous
    January 13, 2011
    Hi Ado.Net Team Will there be support for other Databases like Firebird in the near future? I tried to get a code only demo running. After many different not working approaches I have tried to pass a FbConnection (descendant of DbConnection) to my derived DbContext class and ended up with the exception "Unable to determine the provider name for connection of type 'FirebirdSql.Data.FirebirdClient.FbConnection'.". Is there any way to pass the provider name information to DbContext? Or are there missing things in the FirebirdClient? I am using Version 2.6 of the FirebirdClient which should support EF 4 but maybe not all the new features of CTP 5? Best regrads, Andy

  • Anonymous
    January 17, 2011
    Asked the stored proc caching question on 4 different forums but got no response. Helped us make up out mind it's not the ORM of choice as you can't get a simple yes or no to features. How are you supposed to plan for future products if you have no idea on the development path is beyond me. One thing I will say is ignoring stored procs is a mistake, companies aren't going to drop them and re-write them in code for the sake of a new data access layer., the costs of dev alone is prohibitive.

  • Anonymous
    January 23, 2011
    Excellent stuff, a small question. Let us assume I have data that comes from a service and I would like to use EF CTP4 or CTP5 and I have no database and I do not want a database. Can I pass my data to the wrapper. I mean public class EF4ApplicationPOCOContext : ObjectContext    {       public EF4ApplicationPOCOContext(IServiceLocataor serviceLocator)                 {           ContextOptions.LazyLoadingEnabled = true;           ObjectSet<User> obj = new ObjectSet<User>();           obj.AddObject(serviceLocator.GetUser()); // I do the above for all my dataModel                 }        private ObjectSet<User> _users;        public ObjectSet<User> Users        {            get            {                return _users;            }        } }

  • Anonymous
    January 26, 2011
    The comment has been removed

  • Anonymous
    February 04, 2011
    There is a major issue with deployment on hosted environment that only allow Medium Trust, the EF produces security exceptions.

  • Anonymous
    February 11, 2011
    This is all fantastic.  Been using it for a little while.  My only feature request is better support for the occasional raw SQL and SP that is needed.   Also, I've seen some of the SQL that gets generated and it's not very pretty.  I'm assuming those are some of the things among others that will be fixed in the final version.  Speaking of, when is it going to be out????  Sooner the better!!

  • Anonymous
    February 15, 2011
    Help me please create context class for this model:   public abstract class Publication   {       public int Id { get; set; }       public ICollection<CoAuthor> CoAuthors { get; set; }   }   public class JournalArticle : Publication   {       public int Id { get; set; }       public string ArticleName { get; set; }   }   public class CoAuthor   {       public int Id { get; set; }       public int EmployeeId { get; set; }   } I have:   public class ModelContext : DbContext   {       public DbSet<Publication> Publications { get; set; }       public DbSet<CoAuthor> CoAuthors { get; set; }       protected override void OnModelCreating(ModelBuilder builder)       {           builder.Entity<JournalArticle>().Map(m =>           {               m.MapInheritedProperties();               m.ToTable("JournalArticle", "Science");           });           builder.Entity<CoAuthor>().ToTable("CoAuthor", "Science");       }   } But I give error "Schema specified is not valid. Errors: (35,6) : error 0040: Type Publication is not defined in namespace CodeFirstDatabaseSchema (Alias=Self). (64,8) : error 0100: The referenced EntitySet Publication for End Publication could not be found in the containing EntityContainer." Thank you

  • Anonymous
    February 17, 2011
    Is there a way to disable alphabetical sorting of columns yet?

  • Anonymous
    March 01, 2011
    Hi guys, I have a question regarding type conversion. Assuming I have a column of type "int" on the DB side and I want to have the corresponding property as  a "string" on the entity side. How can I do that using CodeFirst? I have tried the following statement into my EntityTypeConfiguration class: Property(st => st.Id).HasColumnType("int");   // st.Id is a "string" But I get the following error: System.Data.MetadataException : Schema specified is not valid. Errors: (7,6) : error 0063: MaxLength facet isn't allowed for properties of type date. How can I achieve my scenario? Is it possible? Thx