Linq – SubSonic 3 Linq Join Problems

linqsubsonicsubsonic3

using the linqtemplates, I tried getting the linq syntax close to what is in the docs

        var query = from c in db.CountyLookups
                    join s in db.StateLookUps on
                    c.StateLookupID equals
                    s.StateLookupID
                    where c.Name2 == countyName &&
                    s.Abbr == stateAbbr
                    select new
                    {
                        Latitude = c.Latitude,
                        Longitude = c.Longitude
                    };

        var result = query.SingleOrDefault();

but when .SingleOrDefault() is called, I get a yellow screen of darn that says:

System.NotSupportedException: The member 'StateLookupID' is not supported

the stack trace ends up at:

SubSonic.Linq.Structure.TSqlFormatter.VisitMemberAccess(MemberExpression m) 

the StateLookupID column has underscores in the database and is a regular int pk/fk.

what am I doing wrong?

Best Answer

So apparently VisitMemberAccess has no idea what to do with an int, only string and datetime (starting on line 152 of SubSonic.Linq.Structure.TSqlFormatter). I don't know why this would be called on a join, since a join is usually between an int pk/fk (or guid if you like).

I ended up scrapping the linq query in favor of SubSonic.Query.Select. Here is my new code that works:

        var query = db.Select.From<CountyLookup>()
            .InnerJoin<StateLookUp>()
            .Where(CountyLookupTable.Name2Column)
            .IsEqualTo(countyName)
            .And(StateLookUpTable.AbbrColumn)
            .IsEqualTo(stateAbbr);

I then call ExecuteTypedList and map the results back to my model class. Works like buttah. Just wanted to use linq in this case.