亚音速 3 + LINQ 错误 [英] Subsonic 3 + LINQ bug
问题描述
Subsonic 3.0.0.3 的一个奇怪的错误
A weird bug with Subsonic 3.0.0.3
使用 - 作为一个例子 - AdventureWorksLT DB
Using - as an example - AdventureWorksLT DB
当我运行这段代码时
我为 gname 得到了 null(虽然 name 得到的值确定)并且 w 是 0 而不是第一行的值[如果我将选择新的 MyData 更改为仅选择 MyData - 它可以正常工作]
I get null for gname (although name gets the value ok) And w is 0 instead of the value in the 1st row [If I change select new MyData to just select MyData - it works OK]
class Program {
static void Main(string[] args) {
var q = from g in Product.All()
select new MyData{
gname = g.Name,
name = g.Name,
w = g.Weight.Value
};
var list00 = q.Take(1).ToList();
Console.WriteLine(list00[0].gname);
}
}
public class MyData {
public string gname { get; set; }
public string name { get; set; }
public decimal w { get; set; }
}
任何想法有什么问题
谢谢
迈克
推荐答案
是的,我认为当 subsonic 尝试投射到新类型类(非匿名和非源类)时存在错误.
Yes, i think there's a bug when subsonic try to project into new typed class (non anonymous and non source class).
如果您这样做,您的查询将正常工作
Your query will work fine if you do like this
var q = from g in Product.All()
select new{
gname = g.Name,
name = g.Name,
w = g.Weight.Value
};
或者如果你喜欢这个
var q = from g in Product.All()
select g;
作为解决方案,请 fork 我的存储库 (http://github.com/funky81/SubSonic-3.0/commit/aa7a9c1b564b2667db7fbd41e09ab72f5d58dcdb).您可以查看我的源代码并将其应用到您的亚音速代码中.
As a solution, please fork my repository (http://github.com/funky81/SubSonic-3.0/commit/aa7a9c1b564b2667db7fbd41e09ab72f5d58dcdb). You can see my source code and apply it into your subsonic code.
这篇关于亚音速 3 + LINQ 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!