C# linq-to-entities查询中select子句的问题

C# linq-to-entities查询中select子句的问题,c#,performance,entity-framework,linq-to-entities,C#,Performance,Entity Framework,Linq To Entities,您好,我使用代码优先的方法,并定义了以下模型: public partial class tmmodel { public tmmodel() { this.tmmodel_L10n = new HashSet<tmmodel_L10n>(); } public int id { get; set; } public int Order { get; set; }

您好,我使用代码优先的方法,并定义了以下模型:

public partial class tmmodel
    {
        public tmmodel()
        {
            this.tmmodel_L10n = new HashSet<tmmodel_L10n>();
        }

        public int id { get; set; }
        public int Order { get; set; }
        public bool Active { get; set; }

        public virtual ICollection<tmmodel_L10n> tmmodel_L10n { get; set; }
    }


  public partial class tmmodel_L10n
    {
        public int modelid { get; set; }
        public int CultureId { get; set; }
        public string Title { get; set; }
        public string Text { get; set; }

        public virtual tmmodel tmmodel { get; set; }
    }
这是my-linq to entites查询,您可以看到我无权访问Title属性:

 var linqtosqlitems = dc.tmmodel
.Include(x => x.tmmodel_L10n)
.Select(l => new {id = l.id,l.Active,**l.tmmodel_L10n.??**}).ToList();

通过使用include Linq,您可以创建一个可枚举的“子”表,因为它可以是一对多关系。如果您确定“子表”中只有一条记录,您可以这样做:

var linqtosqlitems = dc.tmmodel
.Include(x => x.tmmodel_L10n)
.Select(l => new {id = l.id,l.Active,l.tmmodel_L10n.FirstOrDefault().Title}).ToList();
var linqtosqlitems = dc.tmmodel
.Include(x => x.tmmodel_L10n)
.Select(l => new {id = l.id,l.Active,l.tmmodel_L10n.FirstOrDefault().Title}).ToList();