Question

I'm using EF CodeFirst to generate quite a large schema including TPT tables, e.g.

[Table("MissingReplacementDongles")]
public class MissingReplacementDongle : ReplacementRentalDongle
{
    public virtual bool OriginalStolen { get; set; }
}

public abstract class ReplacementRentalDongle : ConsequentialRentalDongle
{
    public virtual Money ReplacementCharged { get; set; }
}

[Table("ConsequentialRentalDongles")]
public abstract class ConsequentialRentalDongle : RentalDongle
{
}

[Table("RentalDongles")]
public abstract class RentalDongle : BaseConstraint
{
    public virtual DateTime CurrentExpirationDate { get; set; }

    public virtual DateTime? ReturnedDate { get; set; }
}

I've been developing against a SQL Server Express 2008 installation, and this generates the tables perfectly, i.e a ReplacementRentalDongles table with a ReplacementCharged_Id column, which references a Money table.

However, when I run the same code, but using a SQL Server 2008R2 Developer instance, the tables generated are different! In this case, the ReplacementCharged_Id column ends up being generated in the 'base' table BaseConstraint.

Is this a bug in EF 4.3.1, in that a different SQL Server version ends up creating a different Schema? Is EF compatible with SQL 2008R2 ?

Was it helpful?

Solution

Just to let you all know that I managed to fix the problem - by simply upgrading to Entity Framework 5.0 (released just two weeks ago - http://blogs.msdn.com/b/adonet/archive/2012/08/15/ef5-released.aspx )

EF 5.0 has implemented new features which are available if running on .NET 4.5 (which we're not, we're on .NET 4.0). However, EF 5 does run on .NET 4 also, it would also effectively seem to be a roll-up of bug-fixes for EF 4.3.1 when running on .NET 4.

Short version - upgraded the EF DLLs to 5.0 (via NuGet), and the same (correct!) schema is now generated for new databases on SQL 2008 Express AND 2008R2, it works great!

One small caveat - I had to update my source with extra using directives, as the [Table], [InverseProperty] etc attributes have been moved into the System.ComponentModel.DataAnnotations.Schema namespace (they were in the System.ComponentModel.DataAnnotations namespace in EF 4.3.1)

Simple solution - just upgrade!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top