我的代码中有一个多对多的关系,我正在尝试为数据库播种。这是我的种子方法:
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; }
}
我收到两个错误。一,它告诉我我不能将字符串隐式转换为布尔值。我什至不知道我正在尝试这样做。第二,不能将 lambda express 转换为委托,因为块中的返回类型的 soem 不能隐式转换为委托返回类型。这是对 iCollection 的引用吗?