1

We are selecting records from a table AdditionalDetail; this works fine, but it returns data for FullDetails also, which is another model.

How to get records from AdditionalDetailAbstract model only? I want to update say AmountPaid, with small amount of rows it's not an issue, but in a big list of data, it's a performance issue.

We are using ASP.NET Web API.

var additionalData = dbContext.AdditionalDetail 
                              .Where(c => c.AdditionalDetailId == 525 && c.CompanyId == 15)
                              .FirstOrDefault();

public abstract class AdditionalDetailAbstract
{
    [Key]
    public long AdditionalDetailId { get; set; }
    public long DetailsId { get; set; }
    public long CompanyId { get; set; }
    public decimal AmountToBePay { get; set; }
    public decimal AmountPaid { get; set; }
}

public class AdditionalDetail : AdditionalDetailAbstract
{
    public CaseDetail FullDetails { get; set; }
}

How to deal with it? So I can update only AdditionalDetailAbstract model data.

Xinran Shen
  • 8,416
  • 2
  • 3
  • 12
Surendra
  • 19
  • 1

2 Answers2

0

From your question, If you want to select data from AdditionalDetail but only want to select properties from AdditionalDetailAbstract, you can try this code:

var reuslt = _dbcontext.AdditionalDetailAbstract.Where(c => c.AdditionalDetailId == 2 && c.CompanyId == 15)
                .Select(c => new AdditionalDetailAbstract
                {
                    AdditionalDetailId = c.AdditionalDetailId,
                    DetailsId = c.DetailsId,
                    CompanyId = c.CompanyId,
                    AmountToBePay = c.AmountToBePay,
                    AmountPaid = c.AmountPaid
                })
                .FirstOrDefault();

in this code ef core will not select data from related model

enter image description here

Xinran Shen
  • 8,416
  • 2
  • 3
  • 12
0

Actually if "LazyLoadingEnabled" is enabled then it will bring all related model data, which will effect performance.

Disable Lazy Loading in Entity Framework Core

ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
this.ChangeTracker.LazyLoadingEnabled = false;
Surendra
  • 19
  • 1