我使用一個LINQ加入列表<>什麼返回類型?我正在加入下面的多個表格,出現錯誤'Cannot implicitly convert type System.Collections.Generic.List<AnonymousType#1> to System.Collections.Generic.List<CargoTanksDAL.aspnet_Users>
public List<> GetAspnetUsersWithMembershipAndCompany()
{
using (DevCargoEntities db = new DevCargoEntities())
{
var users = from u in db.aspnet_Users
join mem in db.aspnet_Membership on u.UserId equals mem.UserId
join cl in db.CT_CompanyLogIn on u.UserName equals cl.UserLogIn
join companies in db.CT_Companies on cl.CompanyID equals companies.CompanyID
select new
{
u.UserId,
u.UserName,
mem.Email,
mem.IsLockedOut,
mem.IsApproved,
mem.CreateDate,
companies.CompanyName
};
return users.ToList();
}
}
見頂部相關的問題到這個問題 - http://stackoverflow.com/questions/534690/linq-to-sql-return-anonymous-type?rq=1 –
你想要什麼 回來?你應該構造你的Linq查詢來返回你想要的方法返回的內容。如果你已經有了某種用戶類,你可以使用它。 'select new User(){UserId = u.UserId,UserName = u.UserName ...}' – squillman
您正在查詢中創建一個匿名類型。如果您爲查詢定義自己的類型,則可以返回這些類型的列表。 –