This question is a follow up to this question: How to create a list from two values
考虑这一法典:
class MainClass()
{
string MainKey {get;set;}
string MainName {get;set;}
IEnumerable<SmallObject> MainList {get;set}
}
class SmallObject()
{
string SmallKey {get;set}
}
并且
var mainQuery = (from v from DataContext.myTable
select v);
var myQuery = (from v in mainQuery
select new MainClass()
{
MainKey = v.Field1,
MainName = v.Field2,
MainList = new []
{
new SmallObject { SmallKey = v.Field3 },
new SmallObject { SmallKey = v.Field4 },
}
});
var result1 = myQuery.ToList();
//Changing datatypes for optimization reasons in SQLServer2000
var cmd = DataContext.GetCommand(myQuery);
foreach (System.Data.Common.DbParameter param in cmd.Parameters)
{
// nvarchar -> varchar
// decimal -> numeric
}
var result2 = DataContext.Translate<MainClass>(cmd.ExecuteReader()).ToList();
result1.MainList is OK
结果2 首席大法官
最初的询问在SQerver2000上运行非常缓慢,在改变数据类型时(Linq使用Nvarchar和decimal,因为我的数据库使用斜体和数字)我定下来。
因此,我希望结果2与结果1相同,但在进行数据汇编时,情况并非如此。 与此类似。
在这里取得同样结果的任何想法?
我也尝试过匿名的类型,例如:
IEnumerable<object> MainList {get;set;}
...
MainList = new []
{
new { SmallKey = v.Field3},
new { SmallKey = v.Field4},
}
但结果相同: