Linq To Sql问题. [英] Linq To Sql Problem.
问题描述
大家好,
我是linq到sql的初学者,我想在列表中转换此linq查询,为此我创建了一个与字段映射的类.
Hello All,
i am beginner in linq to sql, i want to convert this linq query in List,for that i have created one class that mapped with filed...
/*Class Contain Field return from Linq Query*/
public class CusInfomration
{
public string CustomerName
{
get;
set;
}
public string CustomerID
{
get;
set;
}
public string OrderDate
{
get;
set;
}
public string OrderId
{
get;
set;
}
}
var CustomerFromWash = from p in _NorthWindDataContext.Customers
join q in _NorthWindDataContext.Orders
on p.CustomerID equals q.CustomerID
where p.Region == "WA"
select new
{
CustomerName =Convert.ToString(p.CompanyName),
CustomerID = Convert.ToString(p.CustomerID),
OrderId = Convert.ToString(q.OrderID),
OrderDate = Convert.ToString(q.OrderDate),
};
List<cusinfomration> lstCust = (List<cusinfomration>)CustomerFromWash;
它会给我错误无法转换类型为``System.Data.Linq.DataQuery`1 [<&f; f__AnonymousType3`4 [System.String,System.String,System.String,System.String]]''的对象键入``System.Collections.Generic.List`1 [LinqToSqlExample.CusInfomration]''
请尽可能地回复我
it will give me error Unable to cast object of type ''System.Data.Linq.DataQuery`1[<>f__AnonymousType3`4[System.String,System.String,System.String,System.String]]'' to type ''System.Collections.Generic.List`1[LinqToSqlExample.CusInfomration]''
Pls Reply me as as possible
推荐答案
那是因为LINQ查询不是不是是List<T>
.
使用CustomerFromWash.ToList();
That''s because a LINQ query is not aList<T>
.
useCustomerFromWash.ToList();
这篇关于Linq To Sql问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!