gpt4 book ai didi

c# - Linq to Entities 查询无法执行

转载 作者:行者123 更新时间:2023-11-30 17:58:48 25 4
gpt4 key购买 nike

我正在尝试创建一个包含来自 3 个不同实体的信息的查询对象。当查询执行时,它告诉我 EntityServerException 未处理。我正在使用 DTO 来提取特定的列。这是我的基本 DTO:

public class LeadRestrictionsDto : BasicModelBase
{
private Guid _userId;
private Guid _leadId;
private string _restrictionDescription;
private DateTime? _modified;

[Key]
public Guid UserId
{
get { return _userId; }
set { SetValueAndNotify(() => UserId, ref _userId, value); }
}

public Guid LeadId
{
get { return _leadId; }
set { SetValueAndNotify(() => LeadId, ref _leadId, value); }
}

public string RestrictionDescription
{
get { return _restrictionDescription; }
set { SetValueAndNotify(() => RestrictionDescription, ref _restrictionDescription, value); }
}

public DateTime? Modified
{
get { return _modified; }
set { SetValueAndNotify(() => Modified, ref _modified, value); }
}
}

这是我正在尝试编写的接受参数类型 guid 的查询:

  public List<LeadRestrictionsDto> GetLeadRestrictionListingNow(Guid id)
{

IEnumerable<LeadRestrictionsDto> restrictions = from user in Manager.Users
join lead in Manager.Leads on user.UserId equals lead.OriginalOwnerId
join restriction in Manager.UserRestrictionListings on user.UserId equals restriction.UserId
where user.UserId == id
select new LeadRestrictionsDto
{
Modified = restriction.Modified,
RestrictionDescription = restriction.Description,
UserId = user.UserId,
LeadId = lead.LeadId
};

List<LeadRestrictionsDto> userRestiction = restrictions.ToList(); //Exception occurs here
return userRestiction;
}

这是我得到的确切异常:

Unable to locate type: System.Linq.IQueryable`1[[Prime.Library.Repository.LeadRestrictionsDto, Prime.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Check that the assembly holding this type is available in the bin/exe folder. Also check that both your assemblies and DevForce assemblies have the expected version number on both client and server.

它似乎在尝试在我的 model.edmx 中找到我的 Dto?对不起,如果这听起来很无知。有谁知道我为什么会收到此异常?我在 LINQPad 中玩过这个查询,它可以毫无问题地拉回数据。

最佳答案

我猜这与我们的服务器未更新有关,但我能够通过返回匿名类型来绕过它:

  public List<LeadRestrictionsDto> GetLeadRestrictionListingNow(Guid id)
{

var restrictions = from user in Manager.Users
join lead in Manager.Leads on user.UserId equals lead.OriginalOwnerId
join restriction in Manager.UserRestrictionListings on user.UserId equals restriction.UserId
where user.UserId == id && (restriction.RestrictionId == 100 || restriction.RestrictionId == 200) && restriction.Active == true
select new
{
Modified = restriction.Modified,
RestrictionDescription = restriction.Description,
UserId = user.UserId,
LeadId = lead.LeadId,
FirstName = lead.FirstName,
Created = lead.Created,
LastName = lead.LastName

};


return restrictions.ToList().Select(x=>new LeadRestrictionsDto()
{
Modified = x.Modified,
RestrictionDescription = x.RestrictionDescription,
UserId = x.UserId,
LeadId = x.LeadId,
FirstName = x.FirstName,
Created = x.Created,
LastName = x.LastName
}).ToList();


}

关于c# - Linq to Entities 查询无法执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11870592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com