2016-06-29 14 views
0

私は2つのクラスがあります。System.Data.SqlClient.SqlException:無効な列名「REFERENCE_ID」

public class Product 
{ 
    public Guid Id {get;set;} 
    public IList<Reference> References {get;set;} 
} 

public class Reference 
{ 
    public Guid Id {get;set;} 
} 

どちらのテーブルには、多くの関係に多くを持って、私はコンテキストファイルに追加しました。

modelBuilder.Entity<Product>() 
        .HasMany<Reference>(p => p.References) 
        .WithMany() 
        .Map(pxar => 
        { 
         pxar.MapLeftKey("Product_Id"); 
         pxar.MapRightKey("Reference_Id"); 
         pxar.ToTable("ProductsXReferences"); 
        }); 

問題の解決方法がわかりません。 Web.Configでデータベーステーブルと接続文字列をチェックしました。

+0

まあ、*何か*が間違っています。実行されたSQLクエリはどのように見えますか?そしてあなたは正しいデータベースをチェックしていますか? –

答えて

0

参考になった商品のコレクションがありません。試してみてください:

public class Product 
{ 
    public Guid Id {get;set;} 
    public ICollection<Reference> References {get;set;} 
} 

public class Reference 
{ 
    public Guid Id {get;set;} 
    public ICollection<Product> Products {get;set;} 
} 

modelBuilder.Entity<Product>() 
      .HasMany(p => p.References) 
      .WithMany(r => r.Products) 
      .Map(pxar => 
      { 
       pxar.MapLeftKey("Product_Id"); 
       pxar.MapRightKey("Reference_Id"); 
       pxar.ToTable("ProductsXReferences"); 
      }); 

https://msdn.microsoft.com/en-us/data/hh134698.aspx

+0

これは 'Products'コレクションなしで行うことができます。引数なしの 'WithMany()'は有効なコードです。 –

関連する問題