EF 5,Fluent API:无效的列名“Source_ID”

时间:2013-04-22 10:57:43

标签: c# asp.net asp.net-mvc-3 entity-framework-5 fluent-interface

早上好

我获取无效的列名“Source_ID”。我的模特是:

产物:

public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public Nullable<decimal> PreviousPrice { get; set; }
public string Url { get; set; }
public int SourceID { get; set; }
public int SectionID { get; set; }
public int CategoryID { get; set; }
public Nullable<int> BrandID { get; set; }
public string PublisherProductID { get; set; }
public string PictureFilename { get; set; }
public bool Deleted { get; set; }
public Nullable<int> Score { get; set; }
public string EAN { get; set; }
public string ExtraAttributes { get; set; }
public DateTime LastUpdateDate { get; set; }
public DateTime InsertDate { get; set; }
public string Keywords { get; set; }
public virtual ProductPicture ProductPicture { get; set; }
public virtual Brand Brand { get; set; }
public virtual Source Source { get; set; }
public virtual Category Category { get; set; }
public virtual Section Section { get; set; }
public virtual ICollection<ProductComment> Comments { get; set; }
public virtual ICollection<Like> Likes { get; set; }
public virtual ICollection<Aside> Asides { get; set; }
public virtual ICollection<Wish> Wishlists { get; set; }
public virtual ICollection<UserRecommendation> UserRecommendations { get; set; }
public virtual ICollection<ProductColor> ProductColors { get; set; }
public virtual ICollection<ProductView> ProductViews { get; set; }
public virtual ICollection<PointLog> PointLogs { get; set; }
public virtual ICollection<InvitationLog> InvitationLogs { get; set; }
public virtual ICollection<FeedItem> FeedItems { get; set; }
public virtual ICollection<Sale> Sales { get; set; }
public virtual ICollection<ListProduct> ListProducts { get; set; }
public virtual ICollection<BonusMalus> BonusMalus { get; set; }
public virtual ICollection<ProductHunter> Hunters { get; set; }

产品图谱:

HasKey(e => e.ID);
Property(e => e.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(e => e.Name).IsRequired().HasColumnType("VARCHAR").HasMaxLength(200);
Property(e => e.Description).HasColumnType("VARCHAR").HasMaxLength(4000);
Property(e => e.Price).IsRequired().HasColumnType("Money");
Property(e => e.PreviousPrice).IsOptional().HasColumnType("Money");
Property(e => e.ExtraAttributes).HasColumnType("VARCHAR").IsOptional().HasMaxLength(1000);
Property(e => e.Url).IsRequired().HasColumnType("VARCHAR").HasMaxLength(2048);
Property(e => e.LastUpdateDate).IsOptional();
Property(e => e.InsertDate).IsOptional();
Property(e => e.PictureFilename).HasColumnType("VARCHAR").HasMaxLength(200);
Property(e => e.Deleted).IsRequired();
Property(e => e.EAN).IsOptional().HasColumnType("VARCHAR").HasMaxLength(18);
Property(e => e.PublisherProductID).IsRequired().HasColumnType("VARCHAR").HasMaxLength(100);
Property(e => e.BrandID).IsOptional();
Property(e => e.SourceID).IsRequired();
Property(e => e.Keywords).HasColumnType("VARCHAR").HasMaxLength(500);
ToTable("Products");
HasOptional(t => t.Brand).WithMany(t => t.Products).HasForeignKey(d => d.BrandID);
HasRequired(e => e.Source).WithMany(s => s.Products).HasForeignKey(e => e.SourceID);
HasRequired(e => e.Category).WithMany(c => c.Products).HasForeignKey(e => e.CategoryID);
HasRequired(t => t.Section).WithMany(t => t.Products).HasForeignKey(d => d.SectionID);

来源:

public int ID { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<SourceCategory> SourceCategories { get; set; }
public virtual ICollection<SourceCategoryRule> SourceCategoryRules { get; set; }
public virtual ICollection<WishlistGame> WishlistGames { get; set; }
public virtual ICollection<SourceWebsiteCommission> Commissions { get; set; }
public virtual ICollection<Sale> Sales { get; set; }

来源映射:

HasKey(e => e.ID);
Property(e => e.ID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Property(e => e.Name).IsRequired().HasColumnType("VARCHAR").HasMaxLength(50);
ToTable("Sources");

表格产品&amp;来源已经创建。当我运行我的解决方案时,我遇到了这个问题(无效的列名Source_ID)。也许这是我的映射中的错误。有人有解决方案吗?

0 个答案:

没有答案