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

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.


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).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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