私の問題は、私は解決策を実施したが、それは仕事を得ることができない昨日解決してしまった後、私はこのSolutionEntity Frameworkの - 最初のmのコード:メートルと追加のプロパティ
に加えてOriginal questionに参照のうえです。
モデル::
エントリ:
[Table("NEOV_Entries")]
public class Entry {
[Key]
public int EntryId { get; set; }
[Display(Name = "Request Creation Date")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd.MM.yyyy hh:mm}")]
public DateTime DatasetCreationDate { get; set; }
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
[Required]
public DateTime EntryDate { get; set; }
[Required]
public virtual Employee Employee { get; set; }
public virtual Employee Sponsor { get; set; }
public bool IsResolved { get; set; }
public DateTime? ResolutionDate { get; set; }
public string ResolvedBy { get; set; }
[Display(Name = "Hardware Status")]
public virtual List<EntryHardware> RequestedHardware { get; set; }
[Display(Name = "Workplace Status")]
public ReadyState IsWorkplaceReady { get; set; }
[Display(Name = "Checklist Status")]
public bool IsChecklistArrived { get; set; }
[Display(Name = "Remark")]
public string Comment { get; set; }
public string GetBootstrapRowColor()
{
var diff = (EntryDate - DateTime.Now).Days;
if (IsResolved) {
return "success";
} else if (diff < 0 && !IsResolved) {
return "danger";
} else if (diff < 7 && !IsResolved) {
return "warning";
} else return "";
}
}
ハードウェア:
[Table("NEOV_Hardware")]
public class Hardware {
[Key]
public int HardwareId { get; set; }
[Required]
[StringLength(50)]
public string Description { get; set; }
public override string ToString() {
return Description;
}
}
EntryHardware:
[Table("NEOV_EntryHardware")]
public class EntryHardware {
[Key, Column(Order = 0)]
public int EntryId { get; set; }
[Key, Column(Order = 1)]
public int HardwareId { get; set; }
public virtual Entry Entry { get; set; }
public virtual Hardware Hardware { get; set; }
public HardwareStatus Status { get; set; }
}
11月毎回私はあなたのすべての私のneccessaryモデルにこの時間が表示されます私移行を追加すると、「EntryEntryHardwares」という新しい追加テーブルが作成されます。
の移行は、スニペット:
CreateTable(
"dbo.EntryEntryHardwares",
c => new
{
Entry_EntryId = c.Int(nullable: false),
EntryHardware_EntryId = c.Int(nullable: false),
EntryHardware_HardwareId = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.Entry_EntryId, t.EntryHardware_EntryId, t.EntryHardware_HardwareId })
.ForeignKey("dbo.NEOV_Entries", t => t.Entry_EntryId, cascadeDelete: true)
.ForeignKey("dbo.NEOV_EntryHardware", t => new { t.EntryHardware_EntryId, t.EntryHardware_HardwareId }, cascadeDelete: true)
.Index(t => t.Entry_EntryId)
.Index(t => new { t.EntryHardware_EntryId, t.EntryHardware_HardwareId });
}
私はすでに参加し、モデルを作成し、EFは(NEOV_EntryHardwareと呼ばれる)correspondigテーブルを作成しますが、以下は
CreateTable(
"dbo.NEOV_EntryHardware",
c => new
{
EntryId = c.Int(nullable: false),
HardwareId = c.Int(nullable: false),
Status = c.Int(nullable: false),
Entry_EntryId = c.Int(),
})
.PrimaryKey(t => new { t.EntryId, t.HardwareId })
.ForeignKey("dbo.NEOV_Entries", t => t.Entry_EntryId)
.ForeignKey("dbo.NEOV_Hardware", t => t.HardwareId, cascadeDelete: true)
.Index(t => t.HardwareId)
.Index(t => t.Entry_EntryId);
は、移行スクリプト内の他の表のとおりです。
CreateTable(
"dbo.NEOV_Hardware",
c => new
{
HardwareId = c.Int(nullable: false, identity: true),
Description = c.String(nullable: false, maxLength: 50),
PerformanceType = c.Int(),
FormType = c.Int(),
Size = c.Short(),
MonitorColor = c.Int(),
Discriminator = c.String(nullable: false, maxLength: 128),
})
.PrimaryKey(t => t.HardwareId);
CreateTable(
"dbo.NEOV_Entries",
c => new
{
EntryId = c.Int(nullable: false, identity: true),
DatasetCreationDate = c.DateTime(nullable: false),
EntryDate = c.DateTime(nullable: false),
IsResolved = c.Boolean(nullable: false),
ResolutionDate = c.DateTime(),
ResolvedBy = c.String(),
IsWorkplaceReady = c.Int(nullable: false),
IsChecklistArrived = c.Boolean(nullable: false),
Comment = c.String(),
Employee_Id = c.Int(nullable: false),
Sponsor_Id = c.Int(),
})
.PrimaryKey(t => t.EntryId)
.ForeignKey("dbo.NEOV_Employees", t => t.Employee_Id, cascadeDelete: true)
.ForeignKey("dbo.NEOV_Employees", t => t.Sponsor_Id)
.Index(t => t.Employee_Id)
.Index(t => t.Sponsor_Id);
さらに:
EntryHardware用の独自のリポジトリ(およびコンテキスト内の独自のプロパティなど)を作成する必要がありますかEntryHardwareオブジェクトをEntry.RequestedHardwareリストに割り当てて保存するだけで十分でしょうか?