Bug? ResultsetFields for a TypedView not returning correct fields.

Posts   
 
    
derrick
User
Posts: 40
Joined: 14-Jan-2004
# Posted on: 06-Mar-2007 23:13:50   

HI, I'm using Using LLBLGenPro 2.0.0.0 (feb 14th), adapter scenario, .net 2.0, and sql server 2000.

I have a view named "MetroZip" that joins 3 tables


SELECT   dbo.metro_header.metro_class, dbo.metro_header.metro_description, dbo.metro.metro_type_cd, 
dbo.metro.metro_state_province, dbo.metro.metro_county, dbo.zip.ZIPCode, dbo.zip.City, dbo.zip.County, 
dbo.zip.StateCode
FROM         dbo.metro INNER JOIN
dbo.zip ON dbo.metro.metro_state_province = dbo.zip.StateCode AND 
dbo.metro.metro_county = dbo.zip.County INNER JOIN
dbo.metro_header ON dbo.metro.metro_type_cd = dbo.metro_header.metro_type_cd


I now want to use the generated code to run a query against the mapped typed view MetroZipTypedView. Here's ultimately the SQL I want to execute:


SELECT DISTINCT metro_class, metro_description, metro_type_cd, city FROM ujenziMetroZip where metro_state_province = 'NJ' ORDER BY metro_class ASC


Here's a C# method that I think should do it


        public static MetroZipTypedView GetMetrosForState(string stateCd, string connectionString)
        {
            MetroZipTypedView metroZipTypedView = new MetroZipTypedView();
            RelationPredicateBucket bucket = 
                new RelationPredicateBucket(MetroZipFields.StateCode == stateCd);

            DataAccessAdapter daa = new DataAccessAdapter(connectionString);

            ResultsetFields fields = new ResultsetFields(4);
            fields.DefineField(MetroZipFields.MetroClass, 0);
            fields.DefineField(MetroZipFields.MetroDescription, 1);
            fields.DefineField(MetroZipFields.MetroTypeCd, 2);
            fields.DefineField(MetroZipFields.City, 3);

            ISortExpression sortExpression = new SortExpression(MetroZipFields.MetroClass | SortOperator.Ascending);
            daa.FetchTypedView(fields, metroZipTypedView, bucket, 0, sortExpression, false);

            return metroZipTypedView;
        }


When I run this method the TypedView has the City field populated with the 4th field in the view (metro_state_province) and NOT the City. I've attached a screen shot of the debug visualizer containing the contents of metroZipTypedView.

Is this a bug or am I doing something wrong?

Attachments
Filename File size Added on Approval
visualizer.jpg 29,792 06-Mar-2007 23:14.06 Approved
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 07-Mar-2007 04:08:03   

What does the generated sql look like from your code? Have you changed the view at all since you last refreshed your catalog? I don't see a problem up front with your code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 07-Mar-2007 10:23:51   

I can reproduce the error. Very odd, looking into it.

(edit) Found it. It only affects adapter.

There's a shortcut in the code which causes this. Here's what happens and what you should do instead to make it work.

The typedview fetch logic knows that a view is always a single target, i.e. always the same view. To be able to target the actual view, it grabs the persistence info for the fields passed in, but because it knows it's always the same view, it simply grabs the persistence info for the view in total, instead of for each field individually, as that doesn't matter in normal cases: all fields are part of the view anyway.

As you're fetching part of a typedview, this doesnt match, because you just need the persistenceinfo for the fields passed in.

So instead use FetchTypedList(). This routine determines for every field in the fields passed in the persistence info individually.

You can also opt for fetching the typedview entirely of course, which is the intended behavior.

Frans Bouma | Lead developer LLBLGen Pro
derrick
User
Posts: 40
Joined: 14-Jan-2004
# Posted on: 07-Mar-2007 15:06:20   

Thanks Otis. FetchTypedList does the trick.