1

モーダルと 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; }
    }
}

ご覧のとおり、このテーブルにはロケーション テーブルで生成された外部キーがあります。外部キーを生成ずにこの関係を維持するにはどうすればよいですか?

4

1 に答える 1

0

挿入時、および相対テーブルと参照テーブルの更新と削除時のユーザートリガー!!! しかし、それはかわいくないので、代わりにアプリケーションですべてを制御する必要があります

于 2013-04-20T20:29:15.443 に答える