<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6821731037344467437</id><updated>2011-11-27T16:08:00.338-08:00</updated><category term='linq single method'/><category term='dlinq'/><category term='linq'/><category term='linq to sql'/><category term='datacontext'/><title type='text'>Step-By-Step to DLinq</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://linq-dlinq.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://linq-dlinq.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Premal</name><uri>http://www.blogger.com/profile/02749827055473713481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6J0uVUxo3mU/Skf0ISCZjLI/AAAAAAAABFA/1ufJkJglJuM/S220/Premal+Cherry+Picking.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6821731037344467437.post-6156782856551417752</id><published>2008-01-26T23:06:00.000-08:00</published><updated>2008-01-27T17:41:54.697-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linq to sql'/><category scheme='http://www.blogger.com/atom/ns#' term='linq single method'/><title type='text'>Linq - Start Using It and the Single method explored</title><content type='html'>Let's start off by registering users on your website or you application. You have a very simple form where the user can enter his desired username n password. We will validate if that username is already in use and also make sure that the password is in the required format.&lt;br /&gt;&lt;br /&gt;I am gonna write up some back-end code for a web application when the user enters his information and click on the submit button.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected void btnRegisterUser_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;String _username = tbUsername.Text.Trim().ToLower().Replace("'", "''");&lt;br /&gt;String _password = tbPassword.Text.Trim().ToLower().Replace("'", "''");&lt;br /&gt;&lt;br /&gt;MemberDataContext MemberDC = new MemberDataContext();&lt;br /&gt;Member new_member = new Member();&lt;br /&gt;new_member.Username = _username;&lt;br /&gt;new_member.Password = _password;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt; MemberDC.Members.InsertOnSubmit(new_member);&lt;/span&gt;&lt;br /&gt;MemberDC.SubmitChanges();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I had a tough time inserting data in the database since all the examples out there don't include the line I marked in bold. The line tells the MemberDataContext to insert the new_member object in the Members table. However, the data is not saved until MemberDC.SubmitChanges() is not executed.&lt;br /&gt;&lt;br /&gt;This was the basic example. However, you might not want two users to use the same username on the system. So, you will want to perform validation. From experience, I suggest using the &lt;span style="font-weight: bold;"&gt;Single&lt;/span&gt; method from the collection of LINQ functions. The &lt;span style="font-weight: bold;"&gt;Single &lt;/span&gt;method always tries returns a single row from the database. If the result of the query returns &lt;span style="font-weight: bold;"&gt;zero&lt;/span&gt; or &lt;span style="font-weight: bold;"&gt;more than one &lt;/span&gt;row, an exception is thrown.&lt;br /&gt;&lt;br /&gt;I will modify the btnRegisterUser_Click method to reflect the username validation.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;protected void btnRegisterUser_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt; MemberDataContext MemberDC = new MemberDataContext();&lt;br /&gt; String _username = tbUsername.Text.Trim().ToLower().Replace("'", "''");&lt;br /&gt; try&lt;br /&gt; {&lt;br /&gt;   var member = MemberDC.Members.Single&lt;member&gt;(u =&gt; u.Username == _username);&lt;br /&gt;   //The username is already in use&lt;br /&gt;   return;&lt;br /&gt; }&lt;br /&gt; catch (Exception ex) {}&lt;br /&gt;&lt;br /&gt; String _password = tbPassword.Text.Trim().ToLower().Replace("'", "''");&lt;br /&gt; Member new_member = new Member();&lt;br /&gt; new_member.Username = _username;&lt;br /&gt; new_member.Password = _password;&lt;br /&gt; MemberDC.Members.InsertOnSubmit(new_member);&lt;br /&gt; MemberDC.SubmitChanges();&lt;br /&gt;}&lt;br /&gt;&lt;/member&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Its easy to understand what will happen when a user tries to register an existing username. The Single method will not throw an exception and that means u have to return an error.&lt;br /&gt;&lt;br /&gt;You could use the same concept to login a member.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;protected void btnLoginSubmit_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;String _username = tbUserName.Text.Replace("'", "''").Trim();&lt;br /&gt;String _password = tbPassword.Text.Replace("'", "''").Trim();&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;MembersDataContext MemberDC = new MembersDataContext();&lt;br /&gt;Member member = MemberDC.Members.Single&lt;member&gt;(m =&gt; m.Username == _username &amp;amp;&amp;amp; m.Password == _password);&lt;br /&gt;FormsAuthentication.RedirectFromLoginPage(member.Username.ToString(), true);&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;//Unsuccessful attempt&lt;br /&gt;errorText.Text = "Invalid username/password combination.";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/member&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Earlier in the post, I spoke about validating the password too. There are 2 options.&lt;br /&gt;&lt;br /&gt;1. Modify Member.designer.cs (bad idea bcuz of this warning)&lt;br /&gt;//------------------------------------------------------------------------------&lt;br /&gt;// &lt;auto-generated&gt;&lt;br /&gt;//     This code was generated by a tool.&lt;br /&gt;//     Runtime Version:2.0.50727.1433&lt;br /&gt;//&lt;br /&gt;//     Changes to this file may cause incorrect behavior and will be lost if&lt;br /&gt;//     the code is regenerated.&lt;br /&gt;// &lt;/auto-generated&gt;&lt;br /&gt;//------------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Exploit the concept of partial classes.&lt;br /&gt;&lt;/span&gt;We will create a class file Member.cs and add the following code.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Xml.Linq;&lt;br /&gt;using System.Text.RegularExpressions;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;namespace LinqDemo&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;public partial class Member&lt;br /&gt;{&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;partial&lt;/span&gt; void OnPasswordChanging(string value)&lt;br /&gt;{&lt;br /&gt;    Regex new_password = new Regex("^[A-Z].*?[0-9]$");&lt;br /&gt;    if (new_password.IsMatch(value) == false)&lt;br /&gt;    {&lt;br /&gt;        throw new Exception("Password does not start with a Capital Letter and end in a number");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Note, the namespace marked in bold. If you are missing that, make sure you define the name space in this file as well as Member.deginer.cs. Absence of that code would not allow the compiler to combine both the partial classes. Also, note the partial modifier on the me OnPasswordChanging method. This is a new feature in .net 3.0. More about partial methods &lt;a href="http://blogs.msdn.com/wesdyer/archive/2007/05/23/in-case-you-haven-t-heard.aspx"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Next up, exploring LINQ across relations.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6821731037344467437-6156782856551417752?l=linq-dlinq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linq-dlinq.blogspot.com/feeds/6156782856551417752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6821731037344467437&amp;postID=6156782856551417752' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/6156782856551417752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/6156782856551417752'/><link rel='alternate' type='text/html' href='http://linq-dlinq.blogspot.com/2008/01/linq-start-using-it-and-single-method.html' title='Linq - Start Using It and the Single method explored'/><author><name>Premal</name><uri>http://www.blogger.com/profile/02749827055473713481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6J0uVUxo3mU/Skf0ISCZjLI/AAAAAAAABFA/1ufJkJglJuM/S220/Premal+Cherry+Picking.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6821731037344467437.post-2487656203999567899</id><published>2008-01-26T11:54:00.001-08:00</published><updated>2008-01-26T23:03:56.314-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='datacontext'/><category scheme='http://www.blogger.com/atom/ns#' term='linq to sql'/><category scheme='http://www.blogger.com/atom/ns#' term='dlinq'/><category scheme='http://www.blogger.com/atom/ns#' term='linq'/><title type='text'>Linq - Getting Started</title><content type='html'>Get yourself a copy of Visual Studio 2008. It ships with a LINQ to SQL Designer. The designer will be your best friend throughout the LINQ to SQLing process.&lt;br /&gt;&lt;br /&gt;I shall design a simple schema starting with something very common to websites today - a SQL table storing member information. It has 3 fields.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;ID - auto incrementing integer&lt;/li&gt;&lt;li&gt;Username - char(10)&lt;/li&gt;&lt;li&gt;Password - char(10)&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;Lets dive into the designer.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How to bring up the designer? &lt;/span&gt;&lt;br /&gt;Right-click on App_Code folder under your website and click on &lt;span style="font-weight: bold;"&gt;Add New Item. &lt;/span&gt;Select &lt;span style="font-weight: bold;"&gt;Linq to SQL Classes. &lt;/span&gt;&lt;span&gt;I renamed the file as Member.dbml&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_6J0uVUxo3mU/R5wgfRVjHxI/AAAAAAAAADY/uIhDYTpbR7Q/s1600-h/Add+Linq+to+SQL+Classes.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_6J0uVUxo3mU/R5wgfRVjHxI/AAAAAAAAADY/uIhDYTpbR7Q/s400/Add+Linq+to+SQL+Classes.JPG" alt="" id="BLOGGER_PHOTO_ID_5160034994661564178" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Visual Studio creates Member.dbml and brings up the designer interface.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp3.blogger.com/_6J0uVUxo3mU/R5wkehVjHzI/AAAAAAAAADo/q2yL9gHbM_w/s1600-h/Linq+Designer.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp3.blogger.com/_6J0uVUxo3mU/R5wkehVjHzI/AAAAAAAAADo/q2yL9gHbM_w/s400/Linq+Designer.JPG" alt="" id="BLOGGER_PHOTO_ID_5160039379823173426" border="0" /&gt;&lt;/a&gt;The designer is divided into two panes. The left pane is where one should drag n drop the sql tables. The right pane is where you drop stored procedures which get converted into methods on the classes. We shall explore the left page first.&lt;br /&gt;&lt;br /&gt;To drag n drop sql tables, open the server explorer n connect to the database. I dragged n dropped the Members table. You will notice that Visual Studio will convert the table names from plural to singular. Here, Members is converted to Member.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://bp2.blogger.com/_6J0uVUxo3mU/R5wmXRVjH1I/AAAAAAAAAD4/3UFjtweF_CA/s1600-h/Members.jpg"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://bp2.blogger.com/_6J0uVUxo3mU/R5wmXRVjH1I/AAAAAAAAAD4/3UFjtweF_CA/s400/Members.jpg" alt="" id="BLOGGER_PHOTO_ID_5160041454292377426" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;At this moment, if you open up Member.designer.cs file, these are the contents.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.Linq;&lt;br /&gt;using System.Data.Linq.Mapping;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Linq.Expressions;&lt;br /&gt;using System.Reflection;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;[System.Data.Linq.Mapping.DatabaseAttribute(Name="LinqDemo")]&lt;br /&gt;public partial class MemberDataContext : System.Data.Linq.DataContext&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt; private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();&lt;br /&gt; &lt;br /&gt;  #region Extensibility Method Definitions&lt;br /&gt;  partial void OnCreated();&lt;br /&gt;  partial void InsertMember(Member instance);&lt;br /&gt;  partial void UpdateMember(Member instance);&lt;br /&gt;  partial void DeleteMember(Member instance);&lt;br /&gt;  #endregion&lt;br /&gt; &lt;br /&gt; public MemberDataContext() : &lt;br /&gt;   base(global::System.Configuration.ConfigurationManager.ConnectionStrings["LinqDemoConnectionString"].ConnectionString, mappingSource)&lt;br /&gt; {&lt;br /&gt;  OnCreated();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public MemberDataContext(string connection) : &lt;br /&gt;   base(connection, mappingSource)&lt;br /&gt; {&lt;br /&gt;  OnCreated();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public MemberDataContext(System.Data.IDbConnection connection) : &lt;br /&gt;   base(connection, mappingSource)&lt;br /&gt; {&lt;br /&gt;  OnCreated();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public MemberDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : &lt;br /&gt;   base(connection, mappingSource)&lt;br /&gt; {&lt;br /&gt;  OnCreated();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public MemberDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : &lt;br /&gt;   base(connection, mappingSource)&lt;br /&gt; {&lt;br /&gt;  OnCreated();&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; public System.Data.Linq.Table&lt;Member&gt; Members&lt;br /&gt; {&lt;br /&gt;  get&lt;br /&gt;  {&lt;br /&gt;   return this.GetTable&lt;Member&gt;();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;Basically, Visual Studio creates a DataContext class (in this case MemberDataContext) which will be your conduit to the data stored in the sql tables. The MemberDataContext class has a few constructors. You will mostly need the default constructor.&lt;br /&gt;&lt;br /&gt;Once you save the Member.dbml file, the following code is added to Member.designer.cs&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[Table(Name="dbo.Members")]&lt;br /&gt;public partial class Member : INotifyPropertyChanging, INotifyPropertyChanged&lt;br /&gt;{&lt;br /&gt; &lt;br /&gt;   private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);&lt;br /&gt; &lt;br /&gt;   private int _ID;&lt;br /&gt; &lt;br /&gt;   private string _Username;&lt;br /&gt; &lt;br /&gt;   private string _Password;&lt;br /&gt; &lt;br /&gt;   #region Extensibility Method Definitions&lt;br /&gt;   partial void OnLoaded();&lt;br /&gt;   partial void OnValidate(System.Data.Linq.ChangeAction action);&lt;br /&gt;   partial void OnCreated();&lt;br /&gt;   partial void OnIDChanging(int value);&lt;br /&gt;   partial void OnIDChanged();&lt;br /&gt;   partial void OnUsernameChanging(string value);&lt;br /&gt;   partial void OnUsernameChanged();&lt;br /&gt;   partial void OnPasswordChanging(string value);&lt;br /&gt;   partial void OnPasswordChanged();&lt;br /&gt;   #endregion&lt;br /&gt; &lt;br /&gt;   public Member()&lt;br /&gt;   {&lt;br /&gt;       OnCreated();&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   [Column(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]&lt;br /&gt;   public int ID&lt;br /&gt;   {&lt;br /&gt;       get&lt;br /&gt;       {&lt;br /&gt;           return this._ID;&lt;br /&gt;       }&lt;br /&gt;       set&lt;br /&gt;       {&lt;br /&gt;           if ((this._ID != value))&lt;br /&gt;           {&lt;br /&gt;               this.OnIDChanging(value);&lt;br /&gt;               this.SendPropertyChanging();&lt;br /&gt;               this._ID = value;&lt;br /&gt;               this.SendPropertyChanged("ID");&lt;br /&gt;               this.OnIDChanged();&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   [Column(Storage="_Username", DbType="NChar(10) NOT NULL", CanBeNull=false)]&lt;br /&gt;   public string Username&lt;br /&gt;   {&lt;br /&gt;       get&lt;br /&gt;       {&lt;br /&gt;           return this._Username;&lt;br /&gt;       }&lt;br /&gt;       set&lt;br /&gt;       {&lt;br /&gt;           if ((this._Username != value))&lt;br /&gt;           {&lt;br /&gt;               this.OnUsernameChanging(value);&lt;br /&gt;               this.SendPropertyChanging();&lt;br /&gt;               this._Username = value;&lt;br /&gt;               this.SendPropertyChanged("Username");&lt;br /&gt;               this.OnUsernameChanged();&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   [Column(Storage="_Password", DbType="NChar(10) NOT NULL", CanBeNull=false)]&lt;br /&gt;   public string Password&lt;br /&gt;   {&lt;br /&gt;       get&lt;br /&gt;       {&lt;br /&gt;           return this._Password;&lt;br /&gt;       }&lt;br /&gt;       set&lt;br /&gt;       {&lt;br /&gt;           if ((this._Password != value))&lt;br /&gt;           {&lt;br /&gt;               this.OnPasswordChanging(value);&lt;br /&gt;               this.SendPropertyChanging();&lt;br /&gt;               this._Password = value;&lt;br /&gt;               this.SendPropertyChanged("Password");&lt;br /&gt;               this.OnPasswordChanged();&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   public event PropertyChangingEventHandler PropertyChanging;&lt;br /&gt; &lt;br /&gt;   public event PropertyChangedEventHandler PropertyChanged;&lt;br /&gt; &lt;br /&gt;   protected virtual void SendPropertyChanging()&lt;br /&gt;   {&lt;br /&gt;       if ((this.PropertyChanging != null))&lt;br /&gt;       {&lt;br /&gt;           this.PropertyChanging(this, emptyChangingEventArgs);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt; &lt;br /&gt;   protected virtual void SendPropertyChanged(String propertyName)&lt;br /&gt;   {&lt;br /&gt;       if ((this.PropertyChanged != null))&lt;br /&gt;       {&lt;br /&gt;           this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is the fun part. Visual Studio created a partial class called Member (the name corresponds to name shown in the designer). I hope you know what a partial class is. If not, in simple words, partial classes allow you to define a class across multiple files.&lt;br /&gt;&lt;br /&gt;Notice &lt;span style="font-weight: bold;"&gt;[Table(Name="dbo.Members")] &lt;/span&gt;definition above the class definition. It means that this class has been mapped to the Members table.&lt;br /&gt;&lt;br /&gt;Now, the Member class has 3 private fields of interest.&lt;br /&gt;&lt;ol&gt;&lt;li&gt;private int _ID;&lt;/li&gt;&lt;li&gt;private string _Username;&lt;/li&gt;&lt;li&gt;private string _Password;&lt;/li&gt;&lt;/ol&gt;These correspond to the fields in the Members table. For each private field from the table, you will find the definition of a public property. Lets investigate the ID property.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[Column(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]&lt;br /&gt;  public int ID&lt;br /&gt;  {&lt;br /&gt;      get&lt;br /&gt;      {&lt;br /&gt;          return this._ID;&lt;br /&gt;      }&lt;br /&gt;      set&lt;br /&gt;      {&lt;br /&gt;          if ((this._ID != value))&lt;br /&gt;          {&lt;br /&gt;              this.OnIDChanging(value);&lt;br /&gt;              this.SendPropertyChanging();&lt;br /&gt;              this._ID = value;&lt;br /&gt;              this.SendPropertyChanged("ID");&lt;br /&gt;              this.OnIDChanged();&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The get property is self explanatory. The set property is more interesting. &lt;br /&gt;Lets say you have a page to change the password. A member whose ID is 100 changes his password and you are relying on Linq to generate the sql statements for the update. Linq keeps track of what fields have changed and generates appropriate sql statements.&lt;br /&gt;&lt;br /&gt;So, just by simple drag n drop actions, you have created a Object Mapper for your Member Table.&lt;br /&gt;&lt;br /&gt;Next up, how do you actually start using it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6821731037344467437-2487656203999567899?l=linq-dlinq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linq-dlinq.blogspot.com/feeds/2487656203999567899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6821731037344467437&amp;postID=2487656203999567899' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/2487656203999567899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/2487656203999567899'/><link rel='alternate' type='text/html' href='http://linq-dlinq.blogspot.com/2008/01/linq-getting-started.html' title='Linq - Getting Started'/><author><name>Premal</name><uri>http://www.blogger.com/profile/02749827055473713481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6J0uVUxo3mU/Skf0ISCZjLI/AAAAAAAABFA/1ufJkJglJuM/S220/Premal+Cherry+Picking.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_6J0uVUxo3mU/R5wgfRVjHxI/AAAAAAAAADY/uIhDYTpbR7Q/s72-c/Add+Linq+to+SQL+Classes.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6821731037344467437.post-7582774388091217957</id><published>2008-01-26T11:06:00.000-08:00</published><updated>2008-01-26T21:51:19.660-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='linq to sql'/><category scheme='http://www.blogger.com/atom/ns#' term='dlinq'/><category scheme='http://www.blogger.com/atom/ns#' term='linq'/><title type='text'>Introduction - Linq to SQL or DLinq</title><content type='html'>Hmmm. What can I say here. Most of you must be knowing what LINQ means and more specifically what is DLINQ. I read numerous blogs and articles to understand how LINQ can help  .net developers who believed that Object Relational Mapping is a key to application development.&lt;br /&gt;&lt;br /&gt;LINQ is to .net what Hibernate is to Java. LINQ goes a few steps ahead and facilitates querying not only SQL databases, but also XML, objects, etc. How convenient is that!!! No need to learn SQL and XQuery in detail. And how about not worrying about SQL Stored Procedures. According to me, Stored Procedures are not easy to use, very difficult to master and possess limited functionality. Well, this is not the place to bitch about SPs, so I will move on.&lt;br /&gt;&lt;br /&gt;The purpose of this blog is to educate myself and readers about how DLINQ can be very efficiently used to make the development time brief and the experience enjoyable. I started playing with LINQ a few days ago, and immediately realized I could not use it. Visual Studio Intellisense would not show me the methods I most read about in the drop downs. After some research and help from a friend, we managed to get it working.&lt;br /&gt;&lt;br /&gt;Throughout the entire series, I will be exploring and talking about how to start using DLINQ and explore all the LINQ methods one by one. So stay tuned.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6821731037344467437-7582774388091217957?l=linq-dlinq.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://linq-dlinq.blogspot.com/feeds/7582774388091217957/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6821731037344467437&amp;postID=7582774388091217957' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/7582774388091217957'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6821731037344467437/posts/default/7582774388091217957'/><link rel='alternate' type='text/html' href='http://linq-dlinq.blogspot.com/2008/01/introduction-linq-to-sql-or-dlinq.html' title='Introduction - Linq to SQL or DLinq'/><author><name>Premal</name><uri>http://www.blogger.com/profile/02749827055473713481</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_6J0uVUxo3mU/Skf0ISCZjLI/AAAAAAAABFA/1ufJkJglJuM/S220/Premal+Cherry+Picking.jpg'/></author><thr:total>0</thr:total></entry></feed>
