Entity Framework returning distinct records after join

前端 未结 3 1937
庸人自扰
庸人自扰 2021-01-27 15:37

Consider we have these two entities and one custom object :

    public class  Entiy1
{
    public int Id { get; set; }
    public int DestinationId { get; set;          


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 16:15

    You can use the LINQ join operator like this:

    var results = from e1 in context.Entity1s
                  join e2 in context.Entity2s
                  on e1.DestinationId equals e2.DestinationId
                  select new EntityDTO
                  {
                      DestinationId = e1.DestinationId,
                      Name = e1.Name,
                      JobTitle = e1.JobTitle,
                      DestinationName = e2.DestinationName
                  };
    

提交回复
热议问题