Linq to Entities Query无法执行

时间:2012-08-08 18:12:32

标签: c# entity-framework mvvm linq-to-entities devforce

我试图创建一个包含来自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中使用了这个查询,它可以回收数据而没有任何问题。

1 个答案:

答案 0 :(得分:1)

我想这与我们的服务器没有更新有关,但我能够通过返回一个匿名类型来解决这个问题:

  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();


  }