using linq select with on a partial class

Hello;

I am using a linq statement to populate a datagrid as follows:

 Dim packages = From p In db.Packages _
                       Join d In db.details On p.PackageID Equals (d.MainID) _
                       Where p.statuscode = 1 And (d.InboundDate = datePicker.Value) And d.RecordType = 11 _
                       Select New OMGridData With {.name = d.ConsigneeName}

        PackagesDataView.DataSource = packages

Open in new window


I have named the columes using the dataPropertyName.

This works perfectly, I have created a test class OMGridData that has only one member.

However, instead of creating an entirely new class for this I would like to use a existing class: detailReportClass

detailReportClass has all the members I need and then some - that is the problem, it is creating a colume for every one of them.

How do I limit it?

In other words :

   Dim packages = From p In db.Packages _
                       Join d In db.details On p.PackageID Equals (d.MainID) _
                       Where p.statuscode = 1 And (d.InboundDate = datePicker.Value) And d.RecordType = 11 _
                       Select New detailReportClass With {.Consignee = d.ConsigneeName, .city = d.City}

Open in new window


Creates about 15 columes in my datagrid instead of just the two I want.

Any help would be great - I do this a lot and would rather now create redundant classes.

Thank you!
Joe RuderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nepaluzCommented:
It really depends on what you do with the data once it is in the datagrid. One option would be to set ONLY the columns you want to be visible AFTER setting the datasource, and the rest to invisible.
0
Joe RuderAuthor Commented:
Is Just hiding them really the only way to do this?
0
Joe RuderAuthor Commented:
I will be manipulating the grid data afterwards, setting different values in the rows and then importing them back into the database by stepping through each row.

If this is the best way, is there a way to set them all to not visible at once then just turn on the ones I want?

thank you...
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

nepaluzCommented:
Since you'll be using the data, then your best bet would be to simply show only the columns you want to show, that way, you preserve the structure of the data for saving back.

You have to iterate through them to set them to invisible AFTER setting the datasource, then "switch" on the ones you want
        For Each y As DataGridViewColumn In Me.DataGridView1.Columns
            y.Visible = False
        Next

Open in new window

0
Joe RuderAuthor Commented:
Just one final time -- what other options do I have besides just hiding the columns?  It seems a waste of processing time and memory to import in a bunch of stuff I am not using (these can be large)....

Does anybody know a different way?

I do appreciate the help - I am just double checking.
0
nepaluzCommented:
the last and best resort would be to fine tune your linq statement to include ONLY the columns  data that you require.
0
Joe RuderAuthor Commented:
*That* is what I am trying to do!  That was the entire purpose of the OP.

How do I do that?

In my linq statement I only select 2 fields, yet I am getting them all still.

Do I need to repost this question so somebody who knows how to do it will see it?  I am not trying to be cranky, however, after 5 times all you did was tell me that I should do what I was trying to get help to do in the first place.  I apologize if my OP was not clear.

Thank you,

Joe
0
nepaluzCommented:
In my linq statement I only select 2 fields, yet I am getting them all still.

your linq statement filters on 2 fields NOT selects 2 fields, and here is the proof of the pudding:

Select New detailReportClass With {.Consignee = d.ConsigneeName, .city = d.City}

Open in new window


You have muddled your thinking and confused the select statement to mean that, whereas it merely filters the results.

I have not got access to your class, so I can not make code suggestions to you on that, but I can tell thatyou will have to tweak THAT class to get the result you want. The Linq statement WILL return all the columns of the DB that it queries.

Feel free to re-post your question (no caveat as to whether I will not attempt to respond to that too), however for this thread, I think I have taken you as far as I will, purely because your attitude stinks for someone looking for help. Hopefully I have pointed you in the right direction, and good luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Joe RuderAuthor Commented:
My "attidude" did not stink - the experts 'answer' was to simply re-word my original question and tell me to do that.  However, I did find the answer due to some hints buried in the midst of his masive whining.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.