var CountryCompanyDB = from b in dc.PropertyCompanies where (b.Country.Contains(txtSearch)) select;
Session["CountryCompany"] = CountryCompanyDB.ToList();
if(test==1)
{
var result = (List<PropertyCompany >)Session["CountryCompany"];
}
選擇新的這個工作得很好在LINQ
,但我想
var CountryCompanyDB = from b in dc.PropertyCompanies where (b.Country.Contains(txtSearch)) select new {b.id , b.name};
Session["CountryCompany"] = CountryCompanyDB.ToList();
if(test==1)
{
var result = (List<PropertyCompany new {b.id , b.name}>)Session["CountryCompany"];//does not can this work
}
我要選擇新的Session [ 「CountryCompany」]如何能執行這項工作。
編輯
class kbc {
public Int64 id { get; set; }
public string name { get; set; }
}
var CountryCompanyDB = from b in dc.PropertyCompanies where (b.Country.Contains(txtSearch)) select new { id=b.IdCompany ,name=b.NameCompany} ;
if(test==1)
{
var result = (List<kbc>)Session["CountryCompany"];
}
sayError:
無法轉換類型的對象 'System.Collections.Generic.List 1[<>f__AnonymousType0
2 [System.Int64,System.String]]' 爲類型「系統。 Collections.Generic.List`1 [FullSearch + KBC]
downvote沒有任何評論是不公平的 –