Sign up ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am trying to do a cross-database query without having to enumerate the variable t.

public List<Models.MCMessageCenter> GetMsgCtrsWithReloInfoByUserId(Guid userId)
{
    var t = GetMessageCentersByUserId(userId).ToList();

    List<Models.MCMessageCenter> result;

    using (var ctx = new TEDREntities())
    {
        result = (from n in t
                 join m in ctx.UserAccounts.AsNoTracking() on n.UserId equals m.UserAccountId
                 select new Models.MCMessageCenter
                 {
                     Id = n.Id,
                     MessageTitle = n.MessageTitle,
                     CreatedDate = n.CreatedDate,
                     UserId = n.UserId,
                     Name = m.FirstName + " " + m.LastName,
                     RelatedEntityId = n.RelatedEntityId
                 }).ToList();
    }

t could be very large so I don't want to enumerate it by turning it into a list. Is there a better, more efficient way to perform a cross database query?

Whenever I attempt to keep t as IQueryable, I get an error like "can't query two datasources at once." I can get the exact message if anyone needs.

share|improve this question

1 Answer 1

You can try to replace the .ToList() by an .AsEnumerable(). AsEnumerable() makes a transition from LINQ-to-EF to LINQ-to-Objects. AsEnumerable() does not enumerate the items (lazy enumeration).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.