| |
| Extend a linq class with use of partial class
|
|
|
Location: Blogs Henri Koppen - Developer |
 |
| Posted by: Henri Koppen |
18-9-2008 13:42 |
Using Linq has a lot good features. But sometimes trivial tasks are cumbersome. Displaying extra fields of associated linq classes in a datagridview in a databinding scenario took me more then some hours to achive. I had posted some topics on forums regarding the use of extra display fields in a Linq with databinding scenario.
Here's my situation. In the interface on a left panel I displayed a datagridview of persons. When clicking on a row I saw the details of that person on a form. Here I could change a person and save it. I was using a bindingsource and a linq query to fill the bindingsource. If you want to edit items in a binding source they have to be of one Linq to SQL class (in a .dbml file). A person is linked to an organisation, and to display the organisation name in de detail form is simple. Its something like Person.Organisation.Name. However: To display the organisation name in the DataGridView was not so trivial, using Person.Organisation.Name did not work.
First I used a partial class in the VB file behind the Linq DBML file to override the ToString property to display the Organisationname. But I got stuck when I wanted to display more than just the organisation name.
Using the Partial Class I made I added some extra properties in de Person class like OrganisationName.
this is what it looked like:
Code:
Partial Class Person
Public ReadOnly Property OrganisationName() As String Get Return If(Me.Organisation Is Nothing, "", Me.Organisation.Name) End Get End Property End Class
Property has to be public and ReadOnly. The class Person has to have an association with class Organisation.
In the properties of the datagridview I could fill the DataPropertyName with "OrganisationName".
This really worked for me. |
|
| Permalink |
Trackback |
Comments (6)
Add Comment
|
Coach Handbags |
By Coach Handbags on
16-7-2010 7:29 |
utopia With Coach Handbags of styles and colors to choose from you really can’t go wrong.The heels collection provides everything from the big hit of the season ankle boots, to strappy Nike Air Jordan.After hitting the market in 2004, Tory Burch Cheap Gucci Shoes have become a fashion essential for those looking for the latest in style and surprisingly comfort. Michael Jordan Shoescome in a wide range of variety and styles. The big portion of their market and nike dunk appeal comes from their collection of flats that not only is trendy but is known for their wear ability and comfort.With a wide range of designers and Nike Air Jordan on the market, these fashionista savvy Cheap MBT Shoes can come off the cover of Elle magazine without breaking the bank. |
|
|
|
|
nothing is impossible··· |
By anlia on
26-7-2010 2:53 |
Thanks for your sharing, good job! Are you interested in the gucci outlet series? Topguccishoes.com will be the right place that you have come to. There are many different kinds products of discount gucci shoes for your selection, including gucci handbags, gucci sneakers which content with gucci men shoes, gucci jeans, Gucci Skirt, gucci bikini , gucci belts, Gucci Spicy Underwear, Gucci Wallets, Gucci Jewelry, gucci hats, gucci sunglasses and Women Gucci boots line. Welcome to the discount gucci handbags as well as ugg bailey button boots and buy gucci with the best quality at affordable price. |
|
|
cheap ugg boot store |
By ugg australia on
29-7-2010 4:40 |
| Not even as I shook womens ugg boots and trembled uncontrollably in the trenches, did I forget your ugg boots face. I would sit huddled into the wet mud, terrified, as the ugg australia hails of bullets and mortars crashed down around me. I would clutch my uggs bailey button rifle tightly to my heart, and think again of that very first day we met. I would cry out in bailey button boots fear, as the noise of war beat down around me. But, as I thought ugg boots in uk of you and saw you smiling back at me, everything ugg boots usa around me would be become silent, and I would be with you again for a few precious official ugg boots moments, far from the death and destruction. It would not be ugg classic cardy until I opened my eyes once again, that I would see and hear the carnage of the war around me.I cannot tell you ugg classic cardy boots how strong my love for you was back then, when I returned to you on leave in the September, feeling uggs classic cardy battered, bruised and fragile. We held each other so tight I thought ugg uk we would burst. |
|
|
shi |
By fiwedding on
30-7-2010 3:53 |
supply in stock and custom lace front wigs, full lace wigs, lace wigs, human hair wigs, remy lace front wigs, cheap wigs, cheap, buy, celebrity full lace wigs lace wigs lace wigs sale lace front wigs synthetic front lace wigs A Famous Dresses Shop which sell directly Wedding Dresses, Evening Dress, Bridesmaid Dresses,Prom dresses cheap wedding dresses cheap evening dresses cheap prom dresses cheap evening dresses cheap prom dresses Elegant evening dresses are always associated with the brides and their bridesmaids.Shopping for evening dresses and your wedding dress in stylish bridal ..
|
|
|
|
|
|
|
|
|
|