Store? Linq?

by volkanuzun 10/27/2008 4:21:00 PM

Today while i was reading "Programming Microsoft LINQ" book, i learnt a very interesting attribute of an entity that i like to share.  So let's assume you have Student class which has FirstName, LastName etc members, and let's assume this class is a entity in LINQ; the pseudo code could like this:

[Table] public class Student
{
     [Column]
      public string FirstName{
             get{ return this.FirstName_.ToLower();     }
             set{ this.FirstName_ = value.ToLower();}
     [Column}
     public string LastName{....
}

 

 When you create an instance of this class, and try to change the value of FirstName from the class instance, the getter and setter functions will be called. However when this is a linq entity, this change a little bit. If you try to update a value using linq over here, the scenario changes a little bit. If you use the above code and use linq to update the entity, linq will use getter setter functions. However if you decorate the member with "Storage" such as:

 

[Table] public class Student
{
     [Column(Storage="FirstName_"]
      public string FirstName{
             get{ return this.FirstName_.ToLower();     }
             set{ this.FirstName_ = value.ToLower();}
     [Column}
     public string LastName{....
}

 

Now Linq will skip the getter and setter functions and will directly access to the private member to update it :)

so watch out.

 

 

Tags:

LINQ

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

Volkan Uzun




E-mail me Send mail

Twitter

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Flickr Badge

www.flickr.com
This is a Flickr badge showing public photos from volkanuzun. Make your own badge here.

Disclaimer

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

© Copyright 2009

Sign in