2

To create and assign classes on the fly from other objects I usually use LINQ.

Suppose I have a IQueryable<ProductForCart> object fetched from my Database and, for some reason, I need to create an IQuaryable<Product> where each Product properties are extracted from the ProductForCart.

I simply do:

IQueryable<ProductForCart> productsForCart = ProductRepository.GetProductsForCart();

IQueryable<Product> products = productsForCart.Select(sc => new Product
                                              {
                                                 ProdId = sc.ProdId,
                                                 ProdName = sc.ProdName,
                                                 //other properties
                                              }

This works smooth. But if I have IList<ProductForCart> and IList<Product> it throws a runtime exception:

This function can only be invoked from LINQ to Entities.

I didn't know that LinqToObjects did not support this kind of assignments. Or am I missing something?

CiccioMiami
  • 8,028
  • 32
  • 90
  • 151

1 Answers1

1

You can't use SQLFunctions or EntityFunctions in a Linq-to-Objects query.

You will need to replace those functions with an equivalent .net method

Aducci
  • 26,101
  • 8
  • 63
  • 67