MapSingleType error
I create a project by MVC3 and use EFCode first for DataAccess Layer.
in my DataBase I have PackaginInfo Table, and in project I carete Package Class, this is my code:
public class Package
{
public decimal PackageID { get; set; }
public decimal Title { get; set; }
public decimal Cost { get; set; }
public bool isFree { get; set; }
}
public class ParandShopsEntities : DbContext
{
protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder)
{
modelBuilder.Entity<Package>().MapSingleType().ToTable("PackagingInfo");
}
public DbSet<Package> PackagingInfo { get; set; }
}
when i debug my project i get error: Error System.Data.Entity.ModelConfiguration.EntityTypeConfiguration' does not contain a definition for 'MapSingleType' and no extension method 'MapSingleType' accepting a first argument of type 'System.Data.Entity.M开发者_运维百科odelConfiguration.EntityTypeConfiguration' could be found (are you missing a using directive or an assembly reference?) E:\Projects\ein co\89-11-23\Parand\MvcApplication1\Models\ParandShopsEntities.cs
pls. help me
In CTP5, you now just call
modelBuilder.Entity<Package>().ToTable("PackagingInfo");
Or alternatively you can use TableAttribute data annotations:
[Table("PackagingInfo")]
public class Package
{
public decimal PackageID { get; set; }
public decimal Title { get; set; }
public decimal Cost { get; set; }
public bool isFree { get; set; }
}
Another thing to check is that you rebuilt all t4 templates. If you have changed navigation properties in the edmx file then you should rebuild your t4 templates, otherwise you may get this error.
精彩评论