0

这个问题与这个从未回答过的问题有关。不过,我在这里有一个更真实的例子——所以希望能得到一些帮助。

我有一个拍卖、出价和拍卖细节(一个扁平的表)类。我正在尝试将我的出价包括在拍卖中以及auctiondetail 表中,auction 和auctiondetail 具有相同的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'. 

有什么想法可以让它发挥作用吗?

4

1 回答 1

1

该错误来自 EF4.3(和 4.3.1)。它应该在下一个版本中修复。

升级到实体框架 4.3.1 后查看未处理的异常。他们打算使用迁移系统来解决问题。

于 2012-08-07T08:59:09.653 回答