Creating Data Access Layer Using LINQ To SQL - Stored Procedures
Using Linq to SQL, you can use stored procedure to return your entities.This gives us the advantage of modularity, performance, and security to name a few. We can use these stored procedures with LINQ to SQL. LINQ to SQL maps these database-defined abstractions to code-generated client objects If you want to use the designer, you can go to the server explorer and drag a stored procedure on an existing entity. This would cause the Linq to SQL designer to generate code for calling a stored procedure that returns your entities.Using LINQ you can also call stored procedures when creating a data layer. The LINQ to SQL object relational mapping that ships in .NET 3.5 is flexible and can be used to create data model classes whose object model can be independent of the underlying database schema. It encapsulate business logic and validation rules that work regardless of whether the data model is populated via dynamic SQL or via Stored Procedures.using Stored Procedures with LINQ To SQL is as simple as dragging a Stored Procedure from the Server Explorer Tool to your Visual Designer Surface. Since the Stored Procedure in question, getProvince, generates a list of countryName Classes, I drag the stored procedure from the Server Explorer and drop it on the getProvincel Class on the Visual Designer. This tells the visual designer that the resultset of the stored procedure is a list of Province
Detail Classes. You will then see the stored procedure off to the right of the Visual Designer letting you know it has been added to the DataContext.
The drag-and-drop operation ends up creating a method on your DataContext Class:
[Function(Name="dbo.getProvince")]
public ISingleResult<getProvinceResult> getProvince([Parameter(DbType="BigInt")] System.Nullable<long> country_id)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), country_id);
return ((ISingleResult<getProvinceResult>)(result.ReturnValue));
}
protected void Page_Load(object sender, EventArgs e)
{
var db = new DataClassesDataContext();
var getall = from c in db.getProvince(1)
select c;
foreach (var f in getall)//Written by Aamir Hasan
{
Response.Write(f.pname+"<br>");//studentacad.com
}
}

Author:
Aamir Hasan औथोर:
आमिर हसन أثر
أمير حسن .
2f9f3624-8f3c-434f-a05a-ced58123b4de|0|.0
ALL, asp.net, asp.net 4.0, Linq
asp.net, sql, linq