public object[] PrimaryKey { get { return new object[] { this.UserID }; } } } 下面代码将实现返回linq自动建立的实体(默认情况下,linq不支持这样建立) public IQueryable GetDetailModel() { IQueryable linq1 = from data in new Repository().GetModel() select new UserAddress_Ext { UserID = data.UserID, ID = data.ID, Address = data.Address, }; var linq = from data in LoadRepository().GetModel() join data2 in LoadRepository().GetModel() on data.UserID equals data2.UserID let list = linq1.Where(i => i.UserID == data.UserID) select new User_BasesExt { UserID = data.UserID, UserName = data.UserName, CreateDate = data.CreateDate, Email = data.Email, Status = data.Status, UpdateDate = data.UpdateDate, UserInfos_Extend = data2, UserAddress_Extend = list, }; return linq; }
本文转自博客园张占岭(仓储大叔)的博客,原文链接:linq to sql查询中返回linq自动建立的实体类型),如需转载请自行联系原博主。