1

Is it possible select only specific fields to return. In these example all Tickets including Username. LazyLoading is disabled.

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public string Username { get; set; }
    public DateTime? LastOnline { get; set; }

    public Tickets Tickets { get; set; }
}

Code

var whereQuery= "x => true";
_uow.Users.DbSet.Include("Tickets").Where(whereQuery).OnlyTickets.IncludeUsername();
//or
var whereQuery= "x => true";
_uow.Tickets.DbSet.Include("UserProfile").Where(whereQuery).OnlyTickets.IncludeUsername();

1 Answer 1

2

How about this:

_uow.Users.DbSet.Where(whereQuery).Select(u => new {Tickets = u.Tickets, Username = u.UserName});

You might add there Include(item => item.Tickets) to eager load Tickets prperty but this is not mandatory. If you do not want to use anonymous type you might use Tuple:

_uow.Users.DbSet.Where(whereQuery).Select(u => new Tuple<List<Ticket>,string>(u.Tickets, u.UserName));
Sign up to request clarification or add additional context in comments.

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.