我们正在使用 Entity Framework
private t_Market getMarketByCellsiteID(Guid cellsiteID)
{
try
{
t_Market market = null;
using (LiveLeaseEntities Entities = new LiveLeaseEntities())
{
market = (from m in Entities.t_Market
where m.OperatorId = (from o in Entities.t_CellSite
where o.CellSiteId == Guid.Parse("53B7B160-20C4-4B60-948A-06570E6E3CBA")
select o.OperatorId)
select m).Single();
return market;
}
}
我得到无法将类型“System.Linq.IQueryable”隐式转换为“System.Guid”
最佳答案
我认为这应该可以解决:
private t_Market getMarketByCellsiteID(Guid cellsiteID)
{
try
{
t_Market market = null;
using (LiveLeaseEntities Entities = new LiveLeaseEntities())
{
market = (from m in Entities.t_Market
where m.OperatorId == (from o in Entities.t_CellSite
where o.CellSiteId == Guid.Parse("53B7B160-20C4-4B60-948A-06570E6E3CBA")
select o.OperatorId).Single()
select m).Single();
return market;
}
}
两件事:您需要一个 ==
来与 m.OperatorId
进行比较,并且您正在将它与返回 IQuerable 的 LINQ 查询进行比较——调用LINQ 查询上的 Single() 执行它并返回一个值进行比较。
关于linq - 无法转换为 system.guid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15485996/