コードに多対多の関係があり、データベースをシードしようとしています。これが私のシードメソッドです:
var loc = new List<Location> {
new Location { LocationName = "Paradise Lane" },
new Location { LocationName = "81st Street" }
};
loc.ForEach(l => context.Locations.Add(l));
var soft = new List<Software> {
new Software { Title = "Adobe Creative Suite", ... Locations = loc.Single(s => s.LocationName = "Paradise Lane")}
};
soft.ForEach(s => context.Software.Add(s));
ここに私の場所のクラスがあります:
public class Location
{
public int Id { get; set; }
[Required]
[StringLength(20)]
public string LocationName { get; set; }
public virtual ICollection<Software> Software { get; set; }
}
これが私のソフトウェアクラスです:
public class Software
{
public int Id { get; set; }
[Required]
[StringLength(128)]
public string Title { get; set; }
[Required]
[StringLength(10)]
public string Version { get; set; }
[Required]
[StringLength(128)]
public string SerialNumber { get; set; }
[Required]
[StringLength(3)]
public string Platform { get; set; }
[StringLength(1000)]
public string Notes { get; set; }
[Required]
[StringLength(15)]
public string PurchaseDate { get; set; }
public bool Suite { get; set; }
public string SubscriptionEndDate { get; set; }
//[Required]
//[StringLength(3)]
public int SeatCount { get; set; }
public virtual ICollection<Location> Locations { get; set; }
public virtual ICollection<SoftwarePublisher> Publishers { get; set; }
public virtual ICollection<SoftwareType> Types { get; set; }
}
2 つのエラーが発生しています。1 つ目は、文字列をブール値に暗黙的に変換できないことを示しています。私は自分が帽子をかぶろうとしていたことさえ知りませんでした。そして 2 つ目は、ラムダ エクスプレスをデリゲートに変換できません。これは、ブロック内の戻り値の型がデリゲートの戻り値の型に暗黙的に変換できないためです。それはiCollectionへの参照ですか?