繁体   English   中英

EF Linq将数组连接到表

[英]EF Linq Join an Array to Table

我有以下课程:

public class Coordinate
{
    public string lat { get; set; }
    public string lng { get; set; }
}

我创建了这些对象的数组。

然后,我想确定数组中的任何对象是否与表中的行(经纬度)匹配:

location = db.Locations.Where(u => centers.Any(s => u.Lat.Equals(s.lat)) && 
                                   centers.Any(s => u.Lng.Equals(s.lng)))
                       .ToArray();

但我得到这个例外:

Only primitive types or enumeration types are supported in this context.

您在查询中使用centers类。 这不是类似于System.StringSystem.Int32System.Boolean的原始类型。 你将不得不收集latlng从属性centers全班分成数组或其他IEnumberable<string>实施。

就像是:

var centerLatitudes=(from center in centers
                     select center.lat).toList();
var centerLongitudes=(from center in centers
                      select center.lng).toList();

var locations = 
    db.Locations.Where(loc => centerLatitudes.Any(clt => loc.Lat.Equals(clt.lat)) && 
                              centerLongitudes.Any(clt => loc.Lng.Equals(clt.lng)))
                .ToArray();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM