© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
Raki

Is there a way I can improve this code? I feel its kind of hard to understand

 var plasticWay = await (from plastic in _context.plasticWays 
                 join assetFrom in _context.Assets on plastic.plasticFrom equals assetFrom.Id
                 join assetTo in _context.Assets on plastic.plasticTo equals assetTo.Id
                 join categoryFrom in _context.AssetsCategory on assetFrom.CategoryId equals categoryFrom.Id
                 join categoryTo in _context.AssetsCategory on assetTo.CategoryId equals categoryTo.Id
                 where plastic.Id == id
                 select new plasticWayResponse
                 {
                     Id = plastic.Id,
                     plasticWayFrom = new plasticWayFrom
                     {
                         AssetName = assetFrom.AssetName,
                         AssetCategoryName = categoryFrom.CategoryName
                     },
                     plasticWayTo = new plasticWayTo
                     {
                         AssetName = assetTo.AssetName,
                         AssetCategoryName = categoryTo.CategoryName
                     },
                     Source = plastic.Source,
                     AvailableFrom = plastic.AvailableFrom,
                     AvailableTo = plastic.AvailableTo

                 }).FirstOrDefaultAsync();
 return plasticWay ?? throw new KeyNotFoundException("plasticWayId not found");
 var plasticWay = await (from plastic in _context.plasticWays 
                 join assetFrom in _context.Assets on plastic.plasticFrom equals assetFrom.Id
                 join assetTo in _context.Assets on plastic.plasticTo equals assetTo.Id
                 join categoryFrom in _context.AssetsCategory on assetFrom.CategoryId equals categoryFrom.Id
                 join categoryTo in _context.AssetsCategory on assetTo.CategoryId equals categoryTo.Id
                 where plastic.Id == id
                 select new plasticWayResponse
                 {
                     Id = plastic.Id,
                     plasticWayFrom = new plasticWayFrom
                     {
                         AssetName = assetFrom.AssetName,
                         AssetCategoryName = categoryFrom.CategoryName
                     },
                     plasticWayTo = new plasticWayTo
                     {
                         AssetName = assetTo.AssetName,
                         AssetCategoryName = categoryTo.CategoryName
                     },
                     Source = plastic.Source,
                     AvailableFrom = plastic.AvailableFrom,
                     AvailableTo = plastic.AvailableTo

                 }).FirstOrDefaultAsync();
 return plasticWay ?? throw new KeyNotFoundException("plasticWayId not found");
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

❔ Is there a way to improve this code Performance ?
C#CC# / help
4y ago
❔ Its there a way to fix this?
C#CC# / help
3y ago
✅ how can i improve this code ?
C#CC# / help
2y ago
✅ How can I improve this code?
C#CC# / help
4y ago