モーダルと db コンテキスト クラスに基づいてデータベースを作成するために、コード ファーストのアプローチを使用しています。問題は、あるモデルと次のモデルの間の関係を作成してコードを実行すると、データベースが本来のように外部キーを生成することです。
外部キーなしで、私がどんなに関係を望んでいても。これは、エンティティ フレームワークとコード ファースト アプローチで行うことができますか?
例えば:
namespace LocApp.Models
{
public class Location
{
public int id { get; set; }
[Required]
public string name { get; set; }
[Required]
public string address { get; set; }
[Required]
public string city { get; set; }
[Required]
public string country { get; set; }
[Required]
public string province { get; set; }
[Required]
public string phone { get; set; }
public string fax { get; set; }
public bool active { get; set; }
public virtual ICollection<LocationAssignment> LocationAssignment { get; set; }
}
}
以下と関係があります。
namespace LocApp.Models
{
public class LocationAssignment
{
public int id { get; set; }
public int locationID { get; set; }
public int serviceID { get; set; }
public int productID { get; set; }
public int personID { get; set; }
public virtual Location Location { get; set; }
public virtual Service Service { get; set; }
public virtual Product product { get; set; }
public virtual Person person { get; set; }
}
}
ご覧のとおり、このテーブルにはロケーション テーブルで生成された外部キーがあります。外部キーを生成せずにこの関係を維持するにはどうすればよいですか?