此问题与this question有关,但从未得到答复。我在这里有一个更真实的例子 - 所以希望得到一些帮助。
我有一个拍卖,竞标和拍卖详情(一张扁平的桌子)课程。 我试图在拍卖中包括我的出价以及拍卖品,拍卖和拍卖等具有相同的PK
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
namespace OnCall.VirtualWarehouse.Data.Models.Auctions
{
using System;
public class AuctionCopy
{
public Guid AuctionCopyId { get; set; }
public virtual Collection<BidCopy> BidCopies { get; set; }
}
public class BidCopy
{
public Guid BidCopyId { get; set; }
public Guid AuctionCopyId { get; set; }
public AuctionCopy AuctionCopy { get; set; }
}
public class AuctionDetailCopy
{
[Key]
public Guid AuctionCopyId { get; set; }
public virtual Collection<BidCopy> BidCopies { get; set; }
}
}
这是我的DBContext:
public class DataContext : DbContext
{
static DataContext()
{
Database.SetInitializer(new DropCreateIfChangeInitializer());
}
public DataContext()
{
Configuration.ProxyCreationEnabled = false;
}
public IDbSet<AuctionCopy> AuctionCopy { get; set; }
public IDbSet<BidCopy> BidCopy { get; set; }
public IDbSet<AuctionDetailCopy> AuctionDetailCopy { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
}
public void Seed(DataContext context)
{
}
}
生成数据库时,我得到了
The operation failed because an index or statistics with name 'IX_AuctionId' already exists on table 'Bids'.
我有什么想法可以让它发挥作用吗?
答案 0 :(得分:1)
该错误来自EF4.3(和4.3.1)。 它应该在下一个版本中修复。
查看Unhandled Exception after Upgrading to Entity Framework 4.3.1。他们的目的是使用迁移系统解决方法。