【发布时间】:2012-05-31 16:07:21
【问题描述】:
我正在尝试在我的迁移配置文件中植入一些数据。我创建了一个位置类的新实例
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。
我该如何解决这个问题?
【问题讨论】:
-
知道了。我现在了解 AddOrUpdate 方法。我将其更改为 context.Locations.AddOrUpdate(t => t.Name, location);所以它只检查名称列并且它有效。
标签: entity-framework-4 ef-code-first entity-framework-migrations