2012-08-08 119 views
3

我並不太擅長於將查詢寫在我身上。我試圖創建一個包含來自3個不同實體的信息的查詢對象。當查詢執行時,它告訴我一個EntityServerException未處理。我正在使用DTO來提取特定列。這裏是我的基本DTO:Linq to Entities查詢無法執行

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中玩過這個查詢,並且它沒有問題地將數據拉回來。

+0

你能給的結構和類型的一些細節涉及的項目? – 2012-08-09 09:04:07

回答

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


    }