私は古いアプリケーションをMVC 3に移植し、EFのコードをまず使用して既存のデータベーススキーマを複製したいと考えています。現在のコードベースは、ハードコードされたSQLコマンドで盛り込まれているので、私が考えているモデルは、現在のシステムが期待しているものと "互換性"がなければなりません。私はEFのDatabase Firstを使用することができると知っていますが、既存のスキーマはとてもシンプルなので、まずコードを使用しない理由はありません。古いハードコーディングされたデータベース相互作用。EFコード1対1マッピングと双方向ナビゲーションプロパティ
public class Owner
{
[Key]
public Guid Owner_Id { get; set; }
// Properties
public string ContactName { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
// Navigational properties
public virtual ICollection<Plant> Plants { get; set; }
}
public class Plant
{
[Key]
public Guid Plant_Id { get; set; }
// Properties
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
// Foreign Keys
public Guid Owner_Id { get; set; }
// Navigational properties
public virtual Owner Owner { get; set; }
public virtual License License { get; set; }
}
public class License
{
[Key] public Guid License_Id { get; set; }
// Properties
public int Total { get; set; }
public int Users { get; set; }
public string Key { get; set; }
// Foreign Keys
public Guid Plant_Id { get; set; }
// Navigational properties
public virtual Plant Plant { get; set; }
}
それはコンテキストを作成しようとする上で私は、このエラーを与えている:
を「タイプ間の関連の主要な終了を決定することができません "私はPOCOSが見えるように必要なもの
この関連の主要な終点は、流暢なAPIまたはデータアノテーションのどちらかの関係を使用して明示的に構成されなければなりません。
Plantには、License_Idへのnull可能なFK参照が必要であり、そのライセンスにPlant_IdのFKがあるべきではないことが分かりました。しかし、これらは私が扱っているカードです。私はEFで可能なことをしようとしていますか?それは、これは他の外部キーに同じ外部キーであることを知っているように、ライセンス
// Foreign Keys
public Guid Plant_Id { get; set; }
// Navigational properties
[ForeignKey("Plant_Id")]
public virtual Plant Plant { get; set; }
に追加
を取得しました。「System.Data.Edm.EdmAssociationEnd :: Multiplicity is関係 'License_Plant'のRole 'License_Plant_Source'では有効ではありません。依存ロールのプロパティはキープロパティではないため、依存ロールの多重度の上限は * mustでなければなりません。最終的にはちょっとばかばかしいことが何であるかはわからない... – Stevoman
それは逆だった。 – Birey
まだ、元のエラーを返すことに戻りません。 :( – Stevoman