2016-08-11 2 views
1

私はとても混乱しています。私はカスケード型のドロップダウンを構築しています。私は最も奇妙なエラーを受け取りました。私は次のエラーを受け取ります。(それは長いものです) -モデル作成中に1つ以上の検証エラーが検出されました: r n r n

"モデル生成中に1つ以上の検証エラーが検出されました:\ r \ n \ r \ nAQB_MON.ViewModels.DeviceStatu :: EntityType 'DeviceStatu' has haveキーは定義されていませんこのEntityTypeのキーを定義します\ r \ nAQB_MON.ViewModels.SelectListItem :: EntityType 'SelectListItem'にはキーが定義されていませんこのEntityTypeのキーを定義します\ r \ nDeviceStatus:EntityType:EntitySet 'DeviceStatus'タイプの 'DeviceStatu' 定義されたキーを持たないこと\ Rの\のnSelectListItems:EntityType:のEntitySet 'SelectListItems' が定義されたキーを有していないタイプ 'SelectListItem' に基づいている\ rをする\ n "}

私はメーカーを持っています。テーブルとManufacturerModelテーブル。私のカスケーディングドロップダウンは、最初にメーカーを選択したユーザから構成され、対応するモデルオプションが2番目のドロップダウンで利用可能になります。しかし、私はドロップダウンをロードしようとするとエラーを受け取り続ける。

私は自分のViewModelを作成 - ManufacturerModelContext

public class ManufacturerModelContext : DbContext 
{ 

    public DbSet<Manufacturer> Manufacturers { get; set; } 
    public DbSet<ManufacturerModel> ManufacturerModels { get; set; } 
} 

と私はそれがヴァールメーカーで失敗

//Populate the cascading dropdowns for manufacturer and model 
    ManufacturerModelContext mm = new ManufacturerModelContext(); 
    [HttpGet] 
    public JsonResult GetManufacturers() 
    { 

     var manufacturer = from a in mm.Manufacturers 
          select a.Manufacturer1; 

     return Json(manufacturer.ToList(), JsonRequestBehavior.AllowGet); 

    } 

    public JsonResult GetModelsByManufacturerID(string manufacturerId) 
    { 

     int Id = Convert.ToInt32(manufacturerId); 

     var models = from a in mm.ManufacturerModels where a.ManufacturerID == Id select a; 

     return Json(models); 
    } 

で製造元とモデルを取得します。奇妙なことは、私も持っていないし、決してManufacturerModelモデル

public partial class ManufacturerModel 
{ 
    public ManufacturerModel() 
    { 
     this.Devices = new HashSet<Device>(); 
    } 

    public int ManufacturerModelID { get; set; } 
    [Display(Name="Manufacturer")] 
    public int ManufacturerID { get; set; } 
    public string Model { get; set; } 
    [Display(Name="Model Description")] 
    public string ModelDescription { get; set; } 
    public System.DateTime DATE_CREATED { get; set; } 
    public string CREATED_BY { get; set; } 
    public Nullable<System.DateTime> DATE_MODIFIED { get; set; } 
    public string MODIFIED_BY { get; set; } 

    public virtual ICollection<Device> Devices { get; set; } 
    public virtual Manufacturer Manufacturer { get; set; } 

デバイスモデル

AQB_MON.ViewModels.DeviceStatu

メーカーモデル

public partial class Manufacturer 
{ 
    public Manufacturer() 
    { 
     this.ManufacturerModels = new HashSet<ManufacturerModel>(); 
    } 

    public int ManufacturerID { get; set; } 
    [Display(Name="Manufacturer")] 
    public string Manufacturer1 { get; set; } 
    [Display(Name="Manufacturer Description")] 
    public string ManufacturerDescription { get; set; } 
    public System.DateTime DATE_CREATED { get; set; } 
    public string CREATED_BY { get; set; } 
    public Nullable<System.DateTime> DATE_MODIFIED { get; set; } 
    public string MODIFIED_BY { get; set; } 

    public virtual ICollection<ManufacturerModel> ManufacturerModels { get; set; } 

を持っていたではないかということです

public partial class Device 
{ 
    public Device() 
    { 
     this.DeviceLocations = new HashSet<DeviceLocation>(); 
     this.DeviceLogs = new HashSet<DeviceLog>(); 
     this.DeviceStatus = new HashSet<DeviceStatu>(); 
    } 


    public int DeviceID { get; set; } 
    [Display(Name = "Device Type")] 
    public int DeviceTypeID { get; set; } 
    public int ManufacturerModelID { get; set; } 
    [Display(Name="Inventory Number")] 
    public string InventoryNumber { get; set; } 
    [Display(Name = "Serial Number")] 
    public string SerialNumber { get; set; } 
    [Display(Name = "State ID")] 
    public string StateID { get; set; } 
    [Display(Name = "Date Received")] 
    [DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)] 
    public DateTime? DateReceived { get; set; } 
    public Nullable<decimal> Price { get; set; } 
    public string Notes { get; set; } 
    public System.DateTime DATE_CREATED { get; set; } 
    public string CREATED_BY { get; set; } 
    public Nullable<System.DateTime> DATE_MODIFIED { get; set; } 
    public string MODIFIED_BY { get; set; } 


    public virtual DeviceType DeviceType { get; set; } 
    public virtual ManufacturerModel ManufacturerModel { get; set; } 
    public virtual ICollection<DeviceLocation> DeviceLocations { get; set; } 
    public virtual ICollection<DeviceLog> DeviceLogs { get; set; } 
    public virtual ICollection<DeviceStatu> DeviceStatus { get; set; } 
+0

Manufacturer1とは何ですか?モデルを表示すると役立つことがあります。 –

+0

製造元モデルとManufactureModelモデル –

+0

で質問を更新しましたManufacturerModelにDevice参照がありますが、DbSetは表示されません。 DbSet を追加するか、[NotMapped]をそのナビゲーションプロパティに追加する必要があります。 –

答えて

0

これは、エラーm essage:EntityType 'DeviceStatu'にはキーが定義されていません。このEntityTypeのキーを定義します。

あなたがこのエンティティのデータモデルを投稿できませんでしたが、それは命名問題になる可能性があるため、伝えるのは難しいです

フィールドがDeviceStatusIdなどのクラスと同じ名前を持っているか、[使用しなければならない重要なことにしますKey]フィールド上のデータ注釈

+0

DeviceStatusモデルのキーフィールドに '[Key]'アノテーションを追加する際にエラーが発生し、SelectListItemに '[NotMapped]'アノテーションを追加して解決した 'SelectListItem'で別のエラーが発生しました要素。しかし、これにより、_ CREATE FILEという別のエラーが発生し、オペレーティングシステムエラー5が発生しました(アクセスが拒否されました)。これは解決できませんでした。 –

+0

ああ、投稿しましたか、別の質問へのリンクがありますか? – user2113566

+0

私は質問を投稿しました - CREATE FILEにオペレーティングシステムエラー5が発生しました(アクセスは拒否されました)。 –

関連する問題