Question

I'm trying to create a query object that contains information from 3 different entities. When the query executes, it tells me an EntityServerException was unhandled. I'm using a DTO for specific columns to be pulled. Here's my basic 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); }
    }
}

And here is the query I am trying to write that accepts a guid for a parameter type:

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

Here is the exact exception I get:

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.

It almost seems as if it's trying to find my Dto in my model.edmx? Sorry if that sounds ignorant. Does anyone have an idea why I'm getting this exception? I have played with this query in LINQPad and it pulls data back with no issues.

Was it helpful?

Solution

I guess it had something to do with our server not being updated, but I was able to get around it with returning an anonymous type like so:

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


  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top