【发布时间】:2011-07-19 06:56:11
【问题描述】:
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"];
}
效果很好
但我想要
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"];
}
说错误:
无法将“System.Collections.Generic.List1[<>f__AnonymousType02[System.Int64,System.String]]”类型的对象转换为“System.Collections.Generic.List`1[FullSearch+kbc]
【问题讨论】:
-
没有任何评论的投票是不公平的
标签: c# asp.net linq linq-to-sql generics