linq to sql查询中返回linq自动建立的实体类型)

编辑器加载中... /// /// UserBases扩展类,只在返回实体时用 /// public class User_BasesExt : User_Bases { } /// /// (LINQ) UserBases分部类扩展 /// public partial class User_Bases : IEntity { /// /// 用户详细信息 /// public UserInfos UserInfos_Extend { get; set; } /// /// 用戶地址实体 /// public IQueryable UserAddress_Extend { get; set; } public UserAddress UserAddress { get; set; } /// /// 统一主键 /// 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; }
posted @ 2011-12-03 11:39  张占岭  阅读(1416)  评论(0编辑  收藏  举报