views:

121

answers:

2

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  A: 

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.

Funky81