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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.