C#C
C#17mo ago
Raki

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

c#

 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");
Was this page helpful?