C#C
C#3y ago
kopuo.

❔ Calling extensions method in linq query

Hi, is there any way to use my own extension method in a linq to query? With the approach below, it throws me an exception about the method not being able to be translated to SQL. If I add ..AsEnumerable().Select(...).AsQueryable() will it be a correct solution?

var productsQuery = _dbContext.Products.AsNoTracking().Select(p => new ProductModel
        {
            Name = p.Name,
            Quantity = p.Quantity.MyExtensionMethod(), // p.Quantity == null ? "None" : p.Quantity.ToString()
            Price = p.Price
        });
Was this page helpful?