• Home
  • About
  • Forum
  • News
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,Silverlight,WCF,WPF,NHibernate,Javascript codes exambles articles,Programming exambles.

RSS Feed
  • .NET Matters: Asynchronous HttpWebRequests, Interface Implementation, and More
  • Editor’s Note: New Technologies and a New Magazine
  • .NET Interop: Getting Started With IronRuby And RSpec, Part 1
  • Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus
  • Editor’s Note: Best Practices
  • New Stuff: Resources for Your Developer Toolbox
  • Data Points: LINQ Projection Queries and Alternatives in WCF Services
  • Concurrent Affairs: Solving The Dining Philosophers Problem With Asynchronous Agents
  • DCOM Interop: Generate Custom Managed C++ Wrappers for Easier COM Interoperation Using DCOMSuds
  • Editor’s Note: I Am The Business
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Posted by on October 20, 2010 Leave a comment (7) Go to comments

    Introduction:
    In this article,i am going to explain about the actions between linq api and sql relational database.

    Main:
    LINQ to SQL is a component of the LINQ project that provides the capability to query a relational Microsoft SQL Server database, offering you an object model based on available entities. In other words, you can define a set of objects that represents a thin abstraction layer over the relational data, and you can query this object model by using LINQ queries that are converted into corresponding SQL queries by the LINQ to SQL engine. LINQ to SQL supports Microsoft SQL Server starting from SQL Server 2000 and Microsoft SQL Server Compact starting from version 3.5.

    In LINQ to SQL, you can write a simple query like the following:

    var query =
        from    c in Emps
        where   c.Name == "James"
                && c.Name == "Peter"
        select  new {c.Empid, c.Name, c.Designation };

    This query is converted into an SQL query that is sent to the relational database,

    Select Empid,Name,Designation from Emp where name="James" and name="Peter";

    For ex,Add a sql to linq class,

    Linq Api,

    Once we drag and dropped the relational table in linq api,the mapping and datacontext is created automatically,

    The table object has to be instantiated. To do that, you need an instance of the DataContext class, which defines the bridge between the LINQ world and the external relational database. The nearest concept to DataContext that comes to mind is a database connection—in fact, a mandatory parameter needed to create a DataContext instance is the connection string or the Connection object. Its GetTable method returns a corresponding Table for the specified type:

    DataContext db = new DataContext("");
    Table<Emp>  = db.GetTable<Emp>();

    The DataContext class internally uses the SqlConnection class from ADO.NET. You can pass an existing SqlConnection to the DataContext constructor, and you can also read the connection used by a DataContext instance through its Connection property. All services related to the database connection, such as connection pooling (which is turned on by default), are accessible at the SqlConnection level and are not directly implemented in the DataContext class.

    Any external data must be described with appropriate metadata bound to class definitions. Each table must have a corresponding class decorated with particular attributes. That class corresponds to a row of data and describes all columns in terms of data members of the defined type. The type can be a complete or partial description of an existing physical table, view, or stored procedure result.

    The Linq to sql api will automatically convert the table ad generic class,

    here, Table Tables = …

    Auto generated mapping class between linq api and sql class,

    #pragma warning disable 1591
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.1
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------
     
    namespace Linqdd
    {
    	using System.Data.Linq;
    	using System.Data.Linq.Mapping;
    	using System.Data;
    	using System.Collections.Generic;
    	using System.Reflection;
    	using System.Linq;
    	using System.Linq.Expressions;
    	using System.ComponentModel;
    	using System;
     
     
    	[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="master")]
    	public partial class EmpDataContext : System.Data.Linq.DataContext
    	{
     
    		private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
     
        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void InsertEmp(Emp instance);
        partial void UpdateEmp(Emp instance);
        partial void DeleteEmp(Emp instance);
        #endregion
     
    		public EmpDataContext() : 
    				base(global::System.Configuration.ConfigurationManager.ConnectionStrings["masterConnectionString"].ConnectionString, mappingSource)
    		{
    			OnCreated();
    		}
     
    		public EmpDataContext(string connection) : 
    				base(connection, mappingSource)
    		{
    			OnCreated();
    		}
     
    		public EmpDataContext(System.Data.IDbConnection connection) : 
    				base(connection, mappingSource)
    		{
    			OnCreated();
    		}
     
    		public EmpDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
    				base(connection, mappingSource)
    		{
    			OnCreated();
    		}
     
    		public EmpDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
    				base(connection, mappingSource)
    		{
    			OnCreated();
    		}
     
    		public System.Data.Linq.Table<Emp> Emps
    		{
    			get
    			{
    				return this.GetTable<Emp>();
    			}
    		}
    	}
     
    	[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Emp")]
    	public partial class Emp : INotifyPropertyChanging, INotifyPropertyChanged
    	{
     
    		private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
     
    		private int _Empid;
     
    		private string _FirstName;
     
    		private string _LastName;
     
    		private System.Nullable<int> _Deptid;
     
    		private string _DeptName;
     
    		private string _Salary;
     
    		private string _Manager;
     
        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnEmpidChanging(int value);
        partial void OnEmpidChanged();
        partial void OnFirstNameChanging(string value);
        partial void OnFirstNameChanged();
        partial void OnLastNameChanging(string value);
        partial void OnLastNameChanged();
        partial void OnDeptidChanging(System.Nullable<int> value);
        partial void OnDeptidChanged();
        partial void OnDeptNameChanging(string value);
        partial void OnDeptNameChanged();
        partial void OnSalaryChanging(string value);
        partial void OnSalaryChanged();
        partial void OnManagerChanging(string value);
        partial void OnManagerChanged();
        #endregion
     
    		public Emp()
    		{
    			OnCreated();
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Empid", DbType="Int NOT NULL", IsPrimaryKey=true)]
    		public int Empid
    		{
    			get
    			{
    				return this._Empid;
    			}
    			set
    			{
    				if ((this._Empid != value))
    				{
    					this.OnEmpidChanging(value);
    					this.SendPropertyChanging();
    					this._Empid = value;
    					this.SendPropertyChanged("Empid");
    					this.OnEmpidChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FirstName", DbType="VarChar(20)")]
    		public string FirstName
    		{
    			get
    			{
    				return this._FirstName;
    			}
    			set
    			{
    				if ((this._FirstName != value))
    				{
    					this.OnFirstNameChanging(value);
    					this.SendPropertyChanging();
    					this._FirstName = value;
    					this.SendPropertyChanged("FirstName");
    					this.OnFirstNameChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastName", DbType="VarChar(20)")]
    		public string LastName
    		{
    			get
    			{
    				return this._LastName;
    			}
    			set
    			{
    				if ((this._LastName != value))
    				{
    					this.OnLastNameChanging(value);
    					this.SendPropertyChanging();
    					this._LastName = value;
    					this.SendPropertyChanged("LastName");
    					this.OnLastNameChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Deptid", DbType="Int")]
    		public System.Nullable<int> Deptid
    		{
    			get
    			{
    				return this._Deptid;
    			}
    			set
    			{
    				if ((this._Deptid != value))
    				{
    					this.OnDeptidChanging(value);
    					this.SendPropertyChanging();
    					this._Deptid = value;
    					this.SendPropertyChanged("Deptid");
    					this.OnDeptidChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DeptName", DbType="VarChar(20)")]
    		public string DeptName
    		{
    			get
    			{
    				return this._DeptName;
    			}
    			set
    			{
    				if ((this._DeptName != value))
    				{
    					this.OnDeptNameChanging(value);
    					this.SendPropertyChanging();
    					this._DeptName = value;
    					this.SendPropertyChanged("DeptName");
    					this.OnDeptNameChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Salary", DbType="VarChar(20)")]
    		public string Salary
    		{
    			get
    			{
    				return this._Salary;
    			}
    			set
    			{
    				if ((this._Salary != value))
    				{
    					this.OnSalaryChanging(value);
    					this.SendPropertyChanging();
    					this._Salary = value;
    					this.SendPropertyChanged("Salary");
    					this.OnSalaryChanged();
    				}
    			}
    		}
     
    		[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Manager", DbType="VarChar(20)")]
    		public string Manager
    		{
    			get
    			{
    				return this._Manager;
    			}
    			set
    			{
    				if ((this._Manager != value))
    				{
    					this.OnManagerChanging(value);
    					this.SendPropertyChanging();
    					this._Manager = value;
    					this.SendPropertyChanged("Manager");
    					this.OnManagerChanged();
    				}
    			}
    		}
     
    		public event PropertyChangingEventHandler PropertyChanging;
     
    		public event PropertyChangedEventHandler PropertyChanged;
     
    		protected virtual void SendPropertyChanging()
    		{
    			if ((this.PropertyChanging != null))
    			{
    				this.PropertyChanging(this, emptyChangingEventArgs);
    			}
    		}
     
    		protected virtual void SendPropertyChanged(String propertyName)
    		{
    			if ((this.PropertyChanged != null))
    			{
    				this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    			}
    		}
    	}
    }
    #pragma warning restore 1591

    Conclusion:
    Hope this helps,
    Happy coding.

    Asp.Net
    ← Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net
    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c# →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    7 Comments.

    1. computer repair November 11, 2010 at 10:26 pm

      Nice site, nice and easy on the eyes and great content too.

      Reply
    2. pharmacy technician November 15, 2010 at 9:06 am

      found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

      Reply
    3. nurse practitioner November 26, 2010 at 4:03 pm

      I just added your blog site to my blogroll, I pray you would give some thought to doing the same.

      Reply
    4. college grants December 6, 2010 at 10:57 am

      What a great resource!

      Reply
    5. minority scholarship December 17, 2010 at 2:37 pm

      This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!

      Reply
    6. aspergers syndromes symptoms December 24, 2010 at 12:26 am

      Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!

      Reply

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Trackbacks and Pingbacks:

    • Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping - Pingback on 2010/10/20/ 15:45

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • .NET Matters: Asynchronous HttpWebRequests, Interface Implementation, and More
      • Editor’s Note: New Technologies and a New Magazine
      • .NET Interop: Getting Started With IronRuby And RSpec, Part 1
      • Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus
      • Editor’s Note: Best Practices
    • Search by Tags!

      Advanced application applications architecture ASPNET Basic Basics Bracket Briefs Build building control controls create Custom Cutting developer Drive Editors Entity Forms Foundations Framework Guide inside JavaScript Method Microsoft Points Resources Security Server service Services Silverlight Started Studio Stuff system testing Toolbox Tutorial Using Visual windows
    • Archives

      • October 2011
      • September 2011
      • August 2011
      • July 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • January 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • April 2009
      • February 2008
      • October 2007
      • August 2007
      • July 2007
      • June 2007

    Copyright © 2012 aspdotnetcodesonline.com

    Δ Top
    Social Buttons by Linksku