Entity framework 4 EF代码前4.3:迁移/种子
我正在尝试在迁移配置文件中植入一些数据。我已经创建了location类的一个新实例Entity framework 4 EF代码前4.3:迁移/种子,entity-framework-4,ef-code-first,entity-framework-migrations,Entity Framework 4,Ef Code First,Entity Framework Migrations,我正在尝试在迁移配置文件中植入一些数据。我已经创建了location类的一个新实例 var location = new Location { Name = "Test", Street = "Test", City = "Test", State = "Test", ZipCode = "Test",
var location = new Location
{
Name = "Test",
Street = "Test",
City = "Test",
State = "Test",
ZipCode = "Test",
Country = "US",
PhoneNumber = "Test",
EmailAddress = null,
Website ="Test",
Latitude = Convert.ToDecimal(35.137592),
Longitude = Convert.ToDecimal(-85.124883)
};
为了播种它,我有
context.Locations.AddOrUpdate(
t =>
new
{
t.Name,
t.Street,
t.City,
t.State,
t.ZipCode,
t.Country,
t.PhoneNumber,
t.EmailAddress,
t.Website,
t.Latitude,
t.Longitude
}, location);
纬度和经度都是十进制的?类型
尝试运行此迁移时,我遇到以下错误:
未为类型“System.Nullable”“1[System.Decimal]”和“System.Decimal”定义二进制运算符Equal
如何修复此问题?将其更改为
context.Locations.AddOrUpdate(t => t.Name,location);
所以它只检查名称列(本例中为字符串)得到了它。我现在了解AddOrUpdate方法。我将其更改为context.Locations.AddOrUpdate(t=>t.Name,location);因此,它只会检查Name列,并且有效。