我有一个包含两个表(UserData)和(UserDetails)的数据库。我使用LINQtoEntities。 这里的问题是不接受LINQ查询:
Details = c.ToList<UserDetails>()
错误是:
实例参数:无法转换为&#39; System.Collections.Generic.IEnumerable&lt; mynamespace.UserDetails&gt;&#39; to&#39; System.Collections.Generic.IEnumerable&lt; System.Collections.IEnumerable&gt;&#39;
public class UserData
{
public int Index{ get; set; }
public string Name{ get; set; }
public string PersonalNo { get; set; }
public <List<UserDetails>> Details { get; set; }
}
public struct UserDetails
{
public int Age;
public string profession;
public string gender;
}
public IEnumerable<Userdata> GetUserData()
{
var context = new DatabaseEntities();
var Results =
from a in context.UserData
join b in context.UserDetails on a.Index equals b.Index into c
select new UserData{ Index = a.Index, Name = a.Name, PersonalNo = a.PersonalNo,
Details= c.ToList<UserDetails>() };
return Results;
}
有没有人可以帮助我。如果需要更多信息,请询问。 感谢。
答案 0 :(得分:0)
以下示例正常运行。为了使它工作,你可以使用对象。见下面的例子:
public class UserData
{
public int Index{ get; set; }
public string Name{ get; set; }
public string PersonalNo { get; set; }
public List<object> Details { get; set; }
}
public class UserDetails
{
public int Age;
public string profession;
public string gender;
}
public IEnumerable<Userdata> GetUserData()
{
var context = new DatabaseEntities();
var Results =
from a in context.UserData
join b in context.UserDetails on a.Index equals b.Index into c
select new UserData{ Index = a.Index, Name = a.Name, PersonalNo = a.PersonalNo,
Details= c.ToList<object>() };
return Results;
}
Watch窗口中的Type为“object {MyTestApp.UserDetails}” 所以基本上它正如我所做的那样工作。但我需要适当地施展它。可能现在更容易帮助我。 有什么建议吗?