How to not select Included Table in EF Core

Viewed 39

I have two table that related with each other

public class EMPEmployee
{
    [Key]
    public int? Id { get; set; }

    [Required]
    [StringLength(100)]
    public string? FirstName { get; set; }

    [Required]
    [StringLength(100)]
    public string LastName { get; set; }
    
    public virtual ICollection<InOutRequestLeave>? InOutRequestLeave { get; set; }
}


public class InOutRequestLeave
{
    [Key]
    public int? Id { get; set; }

    [Required]
    [StringLength(10)]
    public string RequestDate { get; set; } = "";
            
    [Required]
    [StringLength(10)]
    public string FromDate { get; set; } = "";

    [Required]
    [StringLength(10)]
    public string ToDate { get; set; } = "";

    [Required]
    public int LeaveDay { get; set; }
              

    public virtual EMPEmployee? EMPEmployee { get; set; }
}

And this is my lambda query for get all data from InOutRequestLeave for any employee in C# Asp.Net Core project :

public async Task<List<InOutRequestLeave>> GetUserAllAsync(EMPEmployee employee)
    {
        return await _uw.GetRepository<InOutRequestLeave>().GetAll(x.EMPEmployee.Id == employee.Id).Include(x => x.EMPEmployee).ToListAsync();
    }  

And this is my Api output using json:

     {
      "requestDate": "1401/05/01",
      "fromDate": "1401/05/01",
      "toDate": "1401/05/01",
      "leaveDay": 1,
      "empEmployee": {
        "firstName": "test",
        "lastName": "testy",
      }

I want to remove "empEmployee" select from output using lambda after including

1 Answers

You can define a new model for this query. By creating a data transform object, you can obtain this data set you need with the help of a method. Thus, you will embody your query.

Related