L
L
LiptonOlolo2021-11-16 08:28:32
C++ / C#
LiptonOlolo, 2021-11-16 08:28:32

EF Core, how to properly drag the required fields?

Good day.
There is a base like this:

Models

public class BaseIdEntity
{
    public int Id { get; set; }
    public bool IsDeleted { get; set; }
}
 
//Основной класс, с которым и производится вся работа.
public class MAOrder : BaseIdEntity
{
    public DateTime DateStart { get; set; }
    public DateTime? DateEnd { get; set; }
    public DateTime? DateComplete { get; set; }
    public DateTime? PaymentDate { get; set; }
    public bool IsPaid { get; set; }
    public decimal Amount { get; set; }
    
    public MACounterparty? Counterparty { get; set; }
    public int? CounterpartyId { get; set; }
    
    public MAOrderStatus? Status { get; set; }
    public int? StatusId { get; set; }
 
    public MAPaymentType? PaymentType { get; set; }
    public int? PaymentTypeId { get; set; }
 
    public ApplicationUser? Creator { get; set; }
    public string? CreatorId { get; set; }
 
    public ApplicationUser? Worker { get; set; }
    public string? WorkerId { get; set; }
 
    public ICollection<MAOrderPosition> Positions { get; set; } //позиции заказа
}
 
public class MACounterparty : BaseIdEntity
{
    public CounterpartyCategory Category { get; set; }
 
    [MARequired]
    public string Name { get; set; }
 
    [MARequired]
    public string Telephone { get; set; }
 
    [EmailAddress]
    public string? EMail { get; set; }
    public string? Comment { get; set; }
 
    public ICollection<MAOrder> Orders { get; set; }
}
 
public class MAOrderPosition : BaseIdEntity
{
    public DateTime DateStart { get; set; }
    public DateTime? DateEnd { get; set; }
    public DateTime? DateComplete { get; set; }
    [MARequired]
    [MAMaxLength(150)]
    public string Description { get; set; }
 
    [MAMaxLength(150)]
    public string? Comment { get; set; }
 
    public decimal Cost { get; set; }
    public decimal CostPrice { get; set; }
    public int Count { get; set; }
    public bool IsReOrder { get; set; }
 
    public MAOrder? Order { get; set; }
    public int? OrderId { get; set; }
    
    public MAOrderStatus? Status { get; set; }
    public int? StatusId { get; set; }
    
    public MAOrderCategory? Category { get; set; }
    public int? CategoryId { get; set; }
}
 
public class NameColor : BaseIdEntity
{
    [MARequired]
    public string Name { get; set; }
    [MARequired]
    public string Color { get; set; }
}
 
public class MAOrderCategory : NameColor
{
    public ICollection<MAOrderPosition> Positions { get; set; }
}
 
public class MAOrderStatus : NameColor
{
    public ICollection<MAOrder> Orders { get; set; }
    public ICollection<MAOrderPosition> Positions { get; set; }
}
 
public class MAPaymentType : BaseIdEntity
{
    public string Name { get; set; }
    public ICollection<MAOrder> Orders { get; set; }
}



There are pages displaying orders (MAOrder), but data is needed there: all NOT navigation properties, counterparty (Counterparty - Only name and phone number), order positions (Positions, all fields except 2), Status (Status).

How to pull such data from the database? A lot of garbage gets through Include (especially to contractors). Through Select - a lot of code. Also, at certain points, you need to supplement Where in order to collect the necessary orders.
What are the Best-practices at this moment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-16
@LiptonOlolo

Select/ Automapper / Mapster . There are no more options.
I would argue about the amount of code - in the case of Select, no one forbids reusing already written code if it is used in many places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question