Request a topic or
Contact an Arke consultant
404-812-3123
Extending LINQ to SQL

Arke Systems Blog

Useful technical and business information straight from Arke.

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Extending LINQ to SQL

We have been experimenting with LINQ to SQL on a couple projects lately and I am constantly impressed.  I'll post some tidbits as I come across some neat features.

Today I had to display the last 4 digits of a customer's credit card number on the UI.  I already have a DBML file in my project and the Customer table has been added to the designer.  Customer has a CreditCardNumber property (ignoring encryption for purposes of this example).  Of course business logic layers aren't new but all too often, you would find logic in the UI that displays the right 4-digits.  But now implementing the BLL is even easier by simply implementing a partial class.

Partial Public Class Customer
    Public Readonly Property Last4 as String
        Get
            Return Right(Me.CreditCardNumber, 4)
        End Get
    End Property
End Class

You can take it one step further and override the CreditCardNumber property and change the Get to return ************XXXX instead of the clear text credit card number, which will make your business logic even more secure.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Eric Stoll on Wednesday, January 02, 2008 1:40 PM
Permalink | Comments (4) | Post RSSRSS comment feed

Related posts

Comments

DotNetKicks.com

Wednesday, January 02, 2008 2:02 PM

trackback

Trackback from DotNetKicks.com

Extending LINQ to SQL

Radek Kozma cz

Sunday, May 11, 2008 3:26 AM

Radek Kozma

This is exactly what I need. But I need to use this property for databinding. This property is not posiible to be seen in Datasource (nor in object properties for databinding) . Object explorer shows everything fine. Manually (from code) I am able bind this property too. Do you know any reason why this property is hidden from datasource designer ?

Eric Stoll us

Sunday, May 11, 2008 11:10 AM

Eric Stoll

If I remember correctly, that designer likes to only show read/write properties. An acceptable workaround, so you aren't going against the business logic, may be to throw a NotImplementedException in the set part of your code.

Radek cz

Monday, May 12, 2008 8:59 AM

Radek

Thanks for your reply. In my solution i have this property read/write. For (simplified) example:

In database table "Something" there is string column "Note". Data should be displayed on the form in upercase, but saving must be done in lowercase. I want to add property "NormalizedNote" and on DatagridView bind one column to this property. It is not possible. If I rewrite designer generated code for my form everything is working fine.

public partial class Something {

public string NormalizedNote
{
get
{
return this.Note.ToUpper();
}

set
{
this.Note = value.ToLower();
}

}

}

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Friday, September 05, 2008 5:12 PM