views:

2102

answers:

1
+1  A: 

Your query seems strange. You should try to simply display

ph = from phys in db.Physicians
     where phys.BQID == bqid
     select phys;

in your grid. That should work. Also, why the calls to Load()? If the DataContext is not disposed when the grid is binding, you should not need it.

If you still have issues, can you please post the error message you get, that would help...

Part 2

The problem is that you have the name is effectively not in the PhysMedGroup. You need to navigate one level down to the MedGroupLookup to access the name, since it is a property of that class.

Depending on the technology you are using (it seems to be either WinForms or Web Forms), you will need to configure your data-binding to access MedGroupLookup.med_group_print_name.

Denis Troller
Yes I figured the loads may not be needed. I revised my question.
cdonner
or, rather, will do that shortly.
cdonner
Then I get this:A field or property with the name 'MedGroupLookup.med_group_print_name' was not found on the selected data source.
cdonner
I understand that the query does not run when it is formed in app, but when the app accesses its data. When I run a database trace, the only query that I see is against the physician_med_group table, but there is no join with the lookup table - because the datasource assignment does not reference the lookup table, and the column declaration in the page is not evaluated at that time. When it is evaluated, it is too late to pull in the names, and the GridView does not interact with IQueryable, but a simple list. So I need some way to make sure the join is done before I assign the datasource.
cdonner
If the DataContext has not been disposed,the simple fact that you access MedGroupLookup should load it. But for performance, you can make it issue a joined query:db.LoadOptions= new LoadOptions();db.LoadOptions.LoadWith<Physician>(x => x.PhysicianMedGroups);db.LoadOptions.LoadWith< PhysicianMedGroup >(x => x.MedGroupLookup);Do that before issueing the query and it should eagerly load the whole query.
Denis Troller
Thanks - I was just reading up on eager loading when I saw your response. Your syntax was not 100% correct, but I got it working and verified that MedGroupLookup is indeed loaded right away. I still can't reference the column:<asp:BoundField HeaderText="Group Name" DataField="MedGroupLookup.med_group_print_name" ></asp:BoundField> gives me the same error, and leaving out MedGroupLookup does, too. Should I try Eval and a template column?
cdonner
Sorry about the syntax, I usually do VB in Visual Studio, not C# in a comment box :). About your problem, I've had it working with a template column and eval syntax, so it might work better (I'm not sure how the BoundField handles property navigation...)
Denis Troller
That was it - it works with Eval. Thanks for your time.
cdonner