I am trying to export an excel using EPPlus 5.0.4 and it works fine in QA and UAT environment, whereas in Prod it is taking so much time. It seems like the calculation I do using the foreach loop takes time. So I refactored the code and made the changes in the repository call. The repo call returns a List of model by taking a List of model as input. I am using the .Net Core 3.1 version and my repo call gives me an error. I tried using IEnumerable and then converted to list and that threw the same error. I don't want to use foreach loop as it takes so much time. How to rectify this error. Any suggestions would be helpful.
public List<StagingProductModel> GetStagingProductDetails(List<ProductModel> productModels)
{
List<StagingProductModel> stagingProductModel = (from prod in _entity.StagingProduct
join cust in _entity.Customer on prod.CustomerId
equals cust.CustomerId
where productModels.Any(x => x.ISBN13 ==
prod.Isbn13 && x.CustomerID == prod.CustomerId)
select new StagingProductModel
{
ProductId = prod.Id,
ISBN13 = prod.Isbn13,
ISBN10 = prod.Isbn10,
CustomerID = cust.CustomerId,
Author = prod.Author,
Title = prod.Title,
PublicationDate = prod.PublicationDate,
CopyRightYear = prod.CopyRightYear,
Edition = prod.Edition,
Comments = prod.Comments,
StagingProductProperties = (from prodproperty in
_entity.StagingProductProperty
join property in
_entity.StagingMasterProperty on
prodproperty.PropertyId equals
property.Property where
prodproperty.ProductId == prod.Id
select new
StagingProductPropertyModel
{
ProductId = prod.Id,
PropertyId = prodproperty.PropertyId,
Value = prodproperty.PropertyValue,
PropertyName = property.PropertyName
}).ToList(),
}).ToList();
}
I get the following error.
The LINQ expression 'DbSet<StagingProduct>
.Join(
outer: DbSet<Customer>,
inner: s => s.CustomerId,
outerKeySelector: c => c.CustomerId,
innerKeySelector: (s, c) => new TransparentIdentifier<StagingProduct, Customer>(
Outer = s,
Inner = c
))
.Where(ti => __proudctModels_0
.Any(x => x.ISBN13 == ti.Outer.Isbn13 && x.CustomerID == ti.Outer.CustomerId))' could not be
translated. Either rewrite the query in a form that can be translated, or switch to client
evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(),
or ToListAsync().
question from:
https://stackoverflow.com/questions/65917913/repository-call-throws-an-error-in-net-core-3-1 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…