【发布时间】:2016-06-02 08:48:02
【问题描述】:
我有数据库表。它的 ORM 是:
public long Id { get; set; }
public System.Guid AttrId { get; set; }
public System.Guid ProdId { get; set; }
public string Value { get; set; }
public virtual Attributes Attributes { get; set; }
public virtual Products Products { get; set; }
你可以看到 value 是一个字符串类型。我正在尝试通过此字段获取最小值和最大值(某些值表示为双精度值)。所以这是我的方法:
public double[] GetMaxMinVals(Guid attrId)
{
double[] res = new double[2];
using(entityContext = new SiteDBEntities())
{
res[0] = entityContext.ProductAttributes.Where(x=>x.AttrId == attrId)
.Min(x => Convert.ToDouble(x.Value));
res[1] = entityContext.ProductAttributes.Where(x => x.AttrId == attrId)
.Max(x => Convert.ToDouble(x.Value));
}
return res;
}
但我得到了例外:
LINQ to Entities 无法识别方法 'Double ToDouble(System.String)' 方法,并且此方法无法转换为存储表达式。
那么如何搜索小数这样的字符串值呢?
【问题讨论】:
标签: c# entity-framework linq