使用下面的简单示例,使用Linq to SQL从多个表返回结果的最佳方法是什么?
说我有两张桌子:
Dogs: Name, Age, BreedId
Breeds: BreedId, BreedName
Run Code Online (Sandbox Code Playgroud)
我想用他们的狗归还所有的狗BreedName.我应该让所有的狗使用这样的东西没有问题:
public IQueryable<Dog> GetDogs()
{
var db = new DogDataContext(ConnectString);
var result = from d in db.Dogs
join b in db.Breeds on d.BreedId equals b.BreedId
select d;
return result;
}
Run Code Online (Sandbox Code Playgroud)
但如果我想要品种的狗并尝试这个我有问题:
public IQueryable<Dog> GetDogsWithBreedNames()
{
var db = new DogDataContext(ConnectString);
var result = from d in db.Dogs
join b in db.Breeds on d.BreedId equals b.BreedId
select new
{
Name = d.Name,
BreedName = b.BreedName
};
return result; …Run Code Online (Sandbox Code Playgroud) 在C#中,我们有var数据类型但我们不能将它用作函数返回类型.
为什么这不可能?
public var myFunction()
{
var = some operations
}Run Code Online (Sandbox Code Playgroud) c# ×1
c#-4.0 ×1
dynamic-data ×1
function ×1
linq ×1
linq-to-sql ×1
return-type ×1
return-value ×1