C
C#3y ago
kopuo

Creating a new view or using unnecessary data?

Hi. I have a view made and used that returns 15 data fields to me. This view is already in use on the system in many places:
var productData = await dbContext.ApiProductsView.AsNoTracking()
.ToListAsync(cancellationToken);
var productData = await dbContext.ApiProductsView.AsNoTracking()
.ToListAsync(cancellationToken);
Now I need to return 4 data fields that this view has. And the question is, will it be more optimal to use this ready view and remap only the necessary fields, or to create a new view only for these 4 data? And would the following usage be correct and optimal?
var productData = await dbContext.ApiProductsView.AsNoTracking()
.Select(x => new ProductInfo
{
field1 = x.field1,
field2 = x.field2,
field3 = x.field3,
field3 = x.field3
})
.ToListAsync(cancellationToken);
var productData = await dbContext.ApiProductsView.AsNoTracking()
.Select(x => new ProductInfo
{
field1 = x.field1,
field2 = x.field2,
field3 = x.field3,
field3 = x.field3
})
.ToListAsync(cancellationToken);
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server