3

我们正在使用实体框架


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”

4

2 回答 2

2

我认为这应该解决它:

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;
    }
}

两件事:您需要 a==与 进行比较m.OperatorId,并且您将它与返回 IQuerable 的 LINQ 查询进行比较——在 LINQ 查询上调用 Single() 会执行它并返回一个要比较的值。

于 2013-03-18T20:16:49.653 回答
1

你的问题是这个比较:

m.OperatorId = (from o in Entities.t_CellSite
    where o.CellSiteId == Guid.Parse("53B7B160-20C4-4B60-948A-06570E6E3CBA")
    select o.OperatorId)

您正在将 a 与 a 进行System.Guid比较System.Linq.IQueryable<System.Guid>。如果您只期望一个结果,您可以这样做:

m.OperatorId = (from o in Entities.t_CellSite
    where o.CellSiteId == Guid.Parse("53B7B160-20C4-4B60-948A-06570E6E3CBA")
    select o.OperatorId).First()
于 2013-03-18T20:15:45.757 回答