问题
A weird bug with Subsonic 3.0.0.3
Using - as an example - AdventureWorksLT DB
When I run this code
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; }
}
Any ideas what is wrong
Thanks
Mike
回答1:
I think there's currently some bugs with projection: http://groups.google.com/group/subsonicproject/browse_thread/thread/2b569539b7f67a34/6f703e0e4ce15141?lnk=gst&q=projection#6f703e0e4ce15141
回答2:
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
};
or if you do like this
var q = from g in Product.All()
select g;
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.
来源:https://stackoverflow.com/questions/1302128/subsonic-3-linq-bug