© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
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
        });
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
        });
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ LINQ, simple query
C#CC# / help
2y ago
❔ Linq Query HELP
C#CC# / help
3y ago
✅ Method calling help
C#CC# / help
3y ago
❔ Calling async method
C#CC# / help
4y ago