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?
 
nepaluzConnect With a Mentor Commented:
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
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.