//--------------------------Table Structure---------------------------
USE [WMMM]
GO
/****** Object: Table [dbo].[MenuMaster] Script Date: 12/23/2009 16:41:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MenuMaster](
[ID] [bigint] NOT NULL,
[Name] [varchar](50) NULL,
[ParentID] [bigint] NULL,
CONSTRAINT [PK_MenuMaster] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
//-------------------------Stored Proc To Retive Data----------------------
USE [WMMM]
GO
/****** Object: StoredProcedure [dbo].[spMenuMasterSelect] Script Date: 12/23/2009 16:43:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spMenuMasterSelect]
AS
BEGIN
SET NOCOUNT ON;
SELECT ID,Name,ParentID from dbo.MenuMaster
END
GO
SET ANSI_PADDING OFF
//----------------------Code To Create Treeview---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Web.UI.WebControls;
using DAL;
/// <summary>
/// Summary description for MenuBLL
/// </summary>
///
public class MenuBLL : IDisposable
{
WMMMDataContext db;
//list of all nodes
SortedList<int, MenuMaster> myMenus = new SortedList<int, MenuMaster>();
//list of all created nodes
SortedList<int, TreeNode> myCreatedNodes = new SortedList<int, TreeNode>();
public MenuBLL()
{
//
// TODO: Add constructor logic here
//
}
public void CreateMenu(MenuBO objMenuBo)
{
TreeView TreeView1 = objMenuBo.LeftTreeView;
TreeView1.Nodes.Clear();
db = new WMMMDataContext();
var found = from o in db.spMenuMasterSelect()
select new { o.ID, o.Name, o.ParentID };
MenuMaster mnuMaster = null;
foreach (var result in found)
{
mnuMaster = new MenuMaster();
mnuMaster.MenuID = Convert.ToInt32(result.ID);
mnuMaster.MenuName = result.Name;
mnuMaster.MenuParentId = Convert.ToInt32(result.ParentID);
myMenus.Add(mnuMaster.MenuID, mnuMaster);
}
TreeNode aNode = null;
foreach (int akey in myMenus.Keys)
{
string code = myMenus[akey].MenuID.ToString();
aNode = new TreeNode(myMenus[akey].MenuName, code);
CreateNode(aNode, TreeView1);
}
}
public void CreateNode(TreeNode aNode, TreeView TreeView1)
{
//This list stores all the nodes id from the current node to the ultimate parent
List<int> myPath = new List<int>();
if (!myCreatedNodes.ContainsValue(aNode))//if the node was not alreazdy created
{
int nodeId = 1001;
nodeId = Convert.ToInt32(aNode.Value);
//Building the current node path untill the ultimate parent
myPath.Add(nodeId);
while (nodeId != 0)
{
if (nodeId != 0)
{
nodeId = myMenus[nodeId].MenuParentId;
myPath.Add(nodeId);
}
}
}
//descending from Ultimate parent until the node
//if the current node does not exists we create it and add it to created nodes collection.
//if it has not a parent we add it to the treeview
//if it has a parent,the parent was already created because we come from it, so we add the current node to the parent.
TreeNode nodeToAdd = null, ParentNodeTofind = null;
for (int j = myPath.Count - 1; j > -1; j--)
{
if (myPath[j] != 0)
{
//checking for each path if the nodes was already created
if (!myCreatedNodes.Keys.Contains(myMenus[myPath[j]].MenuID))
{
//creating the node and adding it to the created nodes collection.
nodeToAdd = new TreeNode(myMenus[myPath[j]].MenuName, myMenus[myPath[j]].MenuID.ToString());
nodeToAdd.NavigateUrl = "../Nodes/Dashboard.aspx?NodeID=" + myMenus[myPath[j]].MenuID.ToString();
myCreatedNodes.Add(myMenus[myPath[j]].MenuID, nodeToAdd);
int parentId = myMenus[myPath[j]].MenuParentId;
//checking if the node has a parent
if (parentId == 0)//this node has no parent we add it to the tree view
{
TreeView1.Nodes.Add(nodeToAdd);
}
else//this node has a parent
{
//rerieving parent node (sure to find it)
ParentNodeTofind = myCreatedNodes[myMenus[myPath[j]].MenuParentId];
//we add the node to its parent childNodes
ParentNodeTofind.ChildNodes.Add(nodeToAdd);
}
}
}
}
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
private bool disposedValue = false;// To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!this.disposedValue)
{
if (disposing)
{
}
// TODO: free managed resources when explicitly called
//if (dbCommand != null)
//{
// dbCommand.Dispose();
// //GC.SuppressFinalize(dbCommand);
//}
}
// TODO: free shared unmanaged resources
this.disposedValue = true;
}
}
public class MenuMaster
{
private string _MenuName;
private int _MenuID;
private int _MenuParentId;
public string MenuName
{
get { return _MenuName; }
set { _MenuName = value; }
}
public int MenuID
{
get { return _MenuID; }
set { _MenuID = value; }
}
public int MenuParentId
{
get { return _MenuParentId; }
set { _MenuParentId = value; }
}
}
//--------------------------Tree View in ASPX Page---------------
<asp:TreeView ID="tvLeftMenu" runat="server" CssClass="input-value" ShowLines="True"
BackColor="Transparent" BorderColor="DarkGray" Font-Bold="True" Font-Size="Small"
ForeColor="Black" ExpandDepth="13" ShowExpandCollapse="false" Width="100px" Font-Names="Times New Roman">
</asp:TreeView>
//-----------------------SQL Table Data-----------------
//------------------------Output Of the Treeview-------------------
//------------------------For LINQ To Stored Proc Visit the following URL
Introduction to Linq To Stored Procedure
Search This Blog
2009-12-20
Create Multi Layer Architecture using WCF
WCF is the Microsoft next generation technology for developing distributed applications.WCF is based on SOA.So,if we want to expose our component as a service,we can use WCF to host the service in IIS,WAS,Self Hosting or managed windows service.
In the following example ,the main component is written in CalculateNumber class which contains a method Calculate.The calculate method takes two integer number and return an integer.So this is the component class.
Now we have created CalculateServiceLayer class in the another project to make the component class(CalculateNumber ) to be available in the WCF Host.So in one side ,it will contain System.ServiceModel namespace for WCF and on the other side it will refer the component class CalculateNumber.
Then as we need to host the service we need a console application projectHost) to hosting the service.The Host application configure the necessary settings like address,binding and contract and start the service in a particular address mentioned in the end point.
Now the service is available for invoking.So we will create a client application (web/windows) to invoke the service.
Lets start the step by step development.
Step 1.Create a Class Library Project "CalculateNumber"
Step 2. Write a method in the class and build your component class CalculateNumber.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateNumber
{
public class CalculateNumber
{
public int Calculate(int x, int y)
{
return x + y;
}
}
}
Step 3.Add a new project (Service Layer) in the solution
Step 4.Choose a class library project and put the project name "CalculateServiceLayer".
Step 5.Add a reference of System.ServiceModel and your component class dll i.e CalculateNumber.dll
Step 6.Modify the class name Class1.cs to ICalculateSevice.cs and copy the entire code in place of existing code in Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculateNumber;
using System.ServiceModel;
namespace CalculateServiceLayer
{
[ServiceContract]
interface ICalculateSevice
{
[OperationContract]
int CalcalculateNumber(int m,int n);
}
}
Step 7.Add an another class file CalculateServiceType.cs and write the following code.Then build your application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculateNumber;
using System.ServiceModel;
namespace CalculateServiceLayer
{
public class CalculateServiceType:ICalculateSevice
{
CalculateNumber.CalculateNumber cn;
#region ICalculateSevice Members
public int CalcalculateNumber(int m, int n)
{
cn=new CalculateNumber.CalculateNumber();
return cn.Calculate(m, n);
}
#endregion
}
}
Step 8.Now add a Host console application in the same solution
Step 9.Add a reference of System.ServiceModel and CalculateServiceLayer.dll.
Open the Program.cs and write the code as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CalculateServiceLayer;
namespace Host
{
class Program
{
static void Main(string[] args)
{
ServiceHost sh = new ServiceHost(typeof(CalculateServiceLayer.CalculateServiceType));
sh.Open();
Console.WriteLine("The Service is ready to use");
Console.ReadKey(true);
sh.Close();
}
}
}
Step 10.Add an App.config file in your Host project
Step 11.Write the necessary configuration in your App.config file as follows
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="CalculateServiceLayer.CalculateServiceType">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="CalculateServiceLayer.ICalculateSevice" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:3333/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Step 12.Now your overall solution structure will be as follows
Step 13.Right click on your Host application and click on "Start new instance" under Debug menu
Step 14.You can see the following console output
Step 15.Now create a web application that will invoke the Wcf service.Right click on the Reference and click on "Add service reference".
Step 16.Put the address "http://localhost:3333/" ,click on Go and then select the service and click OK.Before that make sure your host application is running.
Step 17.Now implement the service in your aspx page as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ImplementCalculateNumber
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.CalculateSeviceClient myproxy = new ImplementCalculateNumber.ServiceReference1.CalculateSeviceClient();
Response.Write(myproxy.CalcalculateNumber(19, 30).ToString());
}
}
}
Step 18.Run your application ,you can see the following output
Step 19.If you modify in the component or service layer,update the service reference in the client (web) application
In the following example ,the main component is written in CalculateNumber class which contains a method Calculate.The calculate method takes two integer number and return an integer.So this is the component class.
Now we have created CalculateServiceLayer class in the another project to make the component class(CalculateNumber ) to be available in the WCF Host.So in one side ,it will contain System.ServiceModel namespace for WCF and on the other side it will refer the component class CalculateNumber.
Then as we need to host the service we need a console application projectHost) to hosting the service.The Host application configure the necessary settings like address,binding and contract and start the service in a particular address mentioned in the end point.
Now the service is available for invoking.So we will create a client application (web/windows) to invoke the service.
Lets start the step by step development.
Step 1.Create a Class Library Project "CalculateNumber"
Step 2. Write a method in the class and build your component class CalculateNumber.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalculateNumber
{
public class CalculateNumber
{
public int Calculate(int x, int y)
{
return x + y;
}
}
}
Step 3.Add a new project (Service Layer) in the solution
Step 4.Choose a class library project and put the project name "CalculateServiceLayer".
Step 5.Add a reference of System.ServiceModel and your component class dll i.e CalculateNumber.dll
Step 6.Modify the class name Class1.cs to ICalculateSevice.cs and copy the entire code in place of existing code in Class1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculateNumber;
using System.ServiceModel;
namespace CalculateServiceLayer
{
[ServiceContract]
interface ICalculateSevice
{
[OperationContract]
int CalcalculateNumber(int m,int n);
}
}
Step 7.Add an another class file CalculateServiceType.cs and write the following code.Then build your application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CalculateNumber;
using System.ServiceModel;
namespace CalculateServiceLayer
{
public class CalculateServiceType:ICalculateSevice
{
CalculateNumber.CalculateNumber cn;
#region ICalculateSevice Members
public int CalcalculateNumber(int m, int n)
{
cn=new CalculateNumber.CalculateNumber();
return cn.Calculate(m, n);
}
#endregion
}
}
Step 8.Now add a Host console application in the same solution
Step 9.Add a reference of System.ServiceModel and CalculateServiceLayer.dll.
Open the Program.cs and write the code as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CalculateServiceLayer;
namespace Host
{
class Program
{
static void Main(string[] args)
{
ServiceHost sh = new ServiceHost(typeof(CalculateServiceLayer.CalculateServiceType));
sh.Open();
Console.WriteLine("The Service is ready to use");
Console.ReadKey(true);
sh.Close();
}
}
}
Step 10.Add an App.config file in your Host project
Step 11.Write the necessary configuration in your App.config file as follows
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="CalculateServiceLayer.CalculateServiceType">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="CalculateServiceLayer.ICalculateSevice" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:3333/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Step 12.Now your overall solution structure will be as follows
Step 13.Right click on your Host application and click on "Start new instance" under Debug menu
Step 14.You can see the following console output
Step 15.Now create a web application that will invoke the Wcf service.Right click on the Reference and click on "Add service reference".
Step 16.Put the address "http://localhost:3333/" ,click on Go and then select the service and click OK.Before that make sure your host application is running.
Step 17.Now implement the service in your aspx page as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ImplementCalculateNumber
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ServiceReference1.CalculateSeviceClient myproxy = new ImplementCalculateNumber.ServiceReference1.CalculateSeviceClient();
Response.Write(myproxy.CalcalculateNumber(19, 30).ToString());
}
}
}
Step 18.Run your application ,you can see the following output
Step 19.If you modify in the component or service layer,update the service reference in the client (web) application
2009-12-19
Introduction to Linq To Stored Procedure
LINQ to SQL provides a runtime infrastructure for managing relational data as objects without losing the ability to query. Your application is free to manipulate the objects while LINQ to SQL stays in the background tracking your changes automatically.It is possible to migrate current ADO.NET solutions to LINQ to SQL in a piecemeal fashion (sharing the same connections and transactions) since LINQ to SQL is simply another component in the ADO.NET family. LINQ to SQL also has extensive support for stored procedures, allowing reuse of the existing enterprise assets. In addition it can filter data in .NET end which are coming from the stored proc.
Following are the steps describe you how LINQ to Stored proc works together.
Step 1-First create a table in your SQL server database-
I have created a table MyTable in the Northwind database.The table contains three feilds(MyID int,MyName Varchar,MyAddress varchar) MyID is a autogenerate number and primary key in this table.
Put some data in yout table
Step 2.Write the following stored proc in your database
-----------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableDelete] Script Date: 12/07/2009 00:08:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableDelete]
(
@MyID int
-- @MyName varchar(50),
-- @MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
DELETE from dbo.MyTable where MyID=@MyID
--SELECT MyID,MyName,MyAddress from dbo.MyTable
END
--select * from MyTable
-------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableInsert] Script Date: 12/07/2009 00:09:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableInsert]
(
@MyName varchar(50),
@MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.MyTable(MyName,MyAddress)VALUES(@MyName,@MyAddress)
END
------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelect] Script Date: 12/07/2009 00:10:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelect]
-- (
-- @MyID int,
-- @MyName varchar(50),
-- @MyAddress varchar(50)
-- )
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
END
--select * from MyTable
----------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelectMulti] Script Date: 12/07/2009 00:10:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelectMulti]
-- (
-- @MyID int
-- @MyName varchar(50),
-- @MyAddress varchar(50)
-- )
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=2
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=1
END
--select * from MyTable
----------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelectMultiWithOutputParam] Script Date: 12/07/2009 00:11:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelectMultiWithOutputParam]
(
@MyID int,
@MyName varchar(50) output
-- @MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
SELECT @MyName=(SELECT MyName from dbo.MyTable where MyID=@MyID)
END
--select * from MyTable
------------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableUpdate] Script Date: 12/07/2009 00:12:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableUpdate]
(
@MyID int,
@MyName varchar(50),
@MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE dbo.MyTable SET MyName=@MyName,MyAddress=@MyAddress
WHERE MyID=@MyID
END
Step 3.Create a new web site in .NET IDE
Step 4.Choose "Add New Item" on your App_Code folder
Step 5.Choose "LINQ to SQL Classes" in yourAdd New Item Dialog and put the file name "MyDataClasses.dbml".
Step 6.Open the MyDataClasses.dbml and modify the name "MyDataContext".Click on "Server Explorer" in MyDataClasses.dbml
Step7.In the Server Explorer click on "Connect to database" icon
Step 8.In "Add Connection" dialog put the server name,database name and required credentials
Step 9.Drag the requird Stored proc in your Method Pane
Step 10.If the Method Pane is not visible,right click on the designer and click on "Show Methods Pane".
Step 11.Now go to your Default.aspx page and create few buttons ,event and a gridview
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdData" runat="server">
</asp:GridView>
</div>
<asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" />
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update" />
<asp:Button ID="btnSelect" runat="server" OnClick="btnSelect_Click" Text="Select" />
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="Delete" />
<asp:Button ID="btnSelectMulti" runat="server" OnClick="btnSelectMulti_Click" Text="SelectMultipleDatatable" />
<asp:Button ID="btnSelectMultiWithOutputParam" runat="server" OnClick="btnSelectMultiWithOutputParam_Click"
Text="SelectMultipleWithOutputParameter" />
</form>
</body>
</html>
Step 12.In the Default.aspx.cs call the required stored procedure for Insert ,update ,select and Delete
MyDataContext db = new MyDataContext();
protected void btnInsert_Click(object sender, EventArgs e)
{
var q3 = db.spMyTableInsert("Indra", "Jadavpur");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var update = db.spMyTableUpdate(2,"Indra", "Jadavpur");
}
protected void btnSelect_Click(object sender, EventArgs e)
{
var Select2 = from o in db.spMyTableSelect()
where o.MyID <= 12 select new { o.MyID, o.MyName, o.MyAddress };
grdData.DataSource = Select2;
grdData.DataBind();
} protected void btnDelete_Click(object sender, EventArgs e)
{
var delete = db.spMyTableDelete(3);
}
Step 13.Now if you like to call a stored proc like dbo.spMyTableSelectMultiWithOutputParam which has a output param write teh follwoing code in your btnSelectMultiWithOutputParam click event
protected void btnSelectMultiWithOutputParam_Click(object sender, EventArgs e)
{
string strCustName = "";
var q2 = db.spMyTableSelectMultiWithOutputParam(1, ref strCustName);
Response.Write(strCustName.ToString());
grdData.DataSource = q2; grdData.DataBind();
}
The spMyTableSelectMultiWithOutputParam is like this
ALTER PROCEDURE dbo.spMyTableSelectMultiWithOutputParam
(
@MyID int, @MyName varchar(50) output
) AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
SELECT @MyName=(SELECT MyName from dbo.MyTable where MyID=@MyID)
END Step
14.Now if you want to call a storedproc which is returning multiple select statement like spMyTableSelectMulti,do the following steps---
The stored proc is like this
ALTER PROCEDURE dbo.spMyTableSelectMulti
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=2
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=1
END
Open the MyDataClassesDesigner.cs and comment the class spMyTableSelectMultiResult .
Then create a new class file clsMultiRecords.cs in App_code and create two partial class spMyTableSelectMultiResult and spMyTableSelectMultiResult2 First Class return the first SQL query and the second one return the second sql query.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Summary description for clsMultiRecords
/// </summary>
public class clsMultiRecords
{
public clsMultiRecords()
{
//
// TODO: Add constructor logic here
//
}
//[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((IMultipleResults)(result.ReturnValue));
//}
public partial class spMyTableSelectMultiResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
public partial class spMyTableSelectMultiResult2
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult2()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
}
Again open the DataClassesDesigner.cs and delete the follwoing portion
[Function(Name = "dbo.spMyTableSelectMulti")]
public ISingleResult spMyTableSelectMulti()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult)(result.ReturnValue));
}
and write the following code in place of that
[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
public IMultipleResults spMyTableSelectMulti()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}
This method will return the IMultipleResults instead of ISingleResult. Mind it,if you open the dbml(MyDataClasses.dbml not MyDataClasses.designer.cs) file and save/modify it, this above portion will be overridden by ISingleResult. Now go to the click event of btnSelectMulti and write the following code
protected void btnSelectMulti_Click(object sender, EventArgs e)
{
IMultipleResults results = new MyDataContext().spMyTableSelectMulti(); List result1 = results.GetResult().ToList();
List result2 = results.GetResult().ToList();
grdData.DataSource = result2;
grdData.DataBind();
}
Step 15.Now run your application ,you can now see the following output,click on different button to obeserve the operation
I am attaching the complete code for Default.aspx.cs ,MyDataContext class and clsMultiRecords.cs
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.Linq;
public partial class _Default : System.Web.UI.Page
{
MyDataContext db = new MyDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsert_Click(object sender, EventArgs e)
{
var q3 = db.spMyTableInsert("Indra", "Jadavpur");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var update = db.spMyTableUpdate(2,"Indra", "Jadavpur");
}
protected void btnSelect_Click(object sender, EventArgs e)
{
var Select2 = from o in db.spMyTableSelect()
where o.MyID <= 12
select new { o.MyID, o.MyName, o.MyAddress };
grdData.DataSource = Select2;
grdData.DataBind();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
var delete = db.spMyTableDelete(3);
}
protected void btnSelectMulti_Click(object sender, EventArgs e)
{
IMultipleResults results = new MyDataContext().spMyTableSelectMulti();
List<clsMultiRecords.spMyTableSelectMultiResult> result1 = results.GetResult<clsMultiRecords.spMyTableSelectMultiResult>().ToList();
List<clsMultiRecords.spMyTableSelectMultiResult2> result2 = results.GetResult<clsMultiRecords.spMyTableSelectMultiResult2>().ToList();
grdData.DataSource = result2;
grdData.DataBind();
}
protected void btnSelectMultiWithOutputParam_Click(object sender, EventArgs e)
{
string strCustName = "";
var q2 = db.spMyTableSelectMultiWithOutputParam(1, ref strCustName);
Response.Write(strCustName.ToString());
grdData.DataSource = q2;
grdData.DataBind();
}
}
MyDataContext class
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
[System.Data.Linq.Mapping.DatabaseAttribute(Name="Northwind")]
public partial class MyDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public MyDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public MyDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
[Function(Name="dbo.spMyTableInsert")]
public int spMyTableInsert([Parameter(Name="MyName", DbType="VarChar(50)")] string myName, [Parameter(Name="MyAddress", DbType="VarChar(50)")] string myAddress)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myName, myAddress);
return ((int)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableUpdate")]
public int spMyTableUpdate([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID, [Parameter(Name="MyName", DbType="VarChar(50)")] string myName, [Parameter(Name="MyAddress", DbType="VarChar(50)")] string myAddress)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID, myName, myAddress);
return ((int)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableSelect")]
public ISingleResult<spMyTableSelectResult> spMyTableSelect()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult<spMyTableSelectResult>)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableDelete")]
public int spMyTableDelete([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID);
return ((int)(result.ReturnValue));
}
//[Function(Name = "dbo.spMyTableSelectMulti")]
//public ISingleResult<spMyTableSelectMultiResult> spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((ISingleResult<spMyTableSelectMultiResult>)(result.ReturnValue));
//}
[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
public IMultipleResults spMyTableSelectMulti()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}
//[Function(Name = "dbo.spMyTableSelectMulti")]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return (IMultipleResults)(result.ReturnValue);
//}
[Function(Name="dbo.spMyTableSelectMultiWithOutputParam")]
public ISingleResult<spMyTableSelectMultiWithOutputParamResult> spMyTableSelectMultiWithOutputParam([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID, [Parameter(Name="MyName", DbType="VarChar(50)")] ref string myName)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID, myName);
myName = ((string)(result.GetParameterValue(1)));
return ((ISingleResult<spMyTableSelectMultiWithOutputParamResult>)(result.ReturnValue));
}
}
public partial class spMyTableSelectResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectResult()
{
}
[Column(Storage="_MyID", DbType="Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage="_MyName", DbType="VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage="_MyAddress", DbType="VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
//public partial class spMyTableSelectMultiResult
//{
// private int _MyID;
// private string _MyName;
// private string _MyAddress;
// public spMyTableSelectMultiResult()
// {
// }
// [Column(Storage="_MyID", DbType="Int NOT NULL")]
// public int MyID
// {
// get
// {
// return this._MyID;
// }
// set
// {
// if ((this._MyID != value))
// {
// this._MyID = value;
// }
// }
// }
// [Column(Storage="_MyName", DbType="VarChar(50)")]
// public string MyName
// {
// get
// {
// return this._MyName;
// }
// set
// {
// if ((this._MyName != value))
// {
// this._MyName = value;
// }
// }
// }
// [Column(Storage="_MyAddress", DbType="VarChar(50)")]
// public string MyAddress
// {
// get
// {
// return this._MyAddress;
// }
// set
// {
// if ((this._MyAddress != value))
// {
// this._MyAddress = value;
// }
// }
// }
//}
public partial class spMyTableSelectMultiWithOutputParamResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiWithOutputParamResult()
{
}
[Column(Storage="_MyID", DbType="Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage="_MyName", DbType="VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage="_MyAddress", DbType="VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
#pragma warning restore 1591
clsMultiRecords.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Summary description for clsMultiRecords
/// </summary>
public class clsMultiRecords
{
public clsMultiRecords()
{
//
// TODO: Add constructor logic here
//
}
//[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((IMultipleResults)(result.ReturnValue));
//}
public partial class spMyTableSelectMultiResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
public partial class spMyTableSelectMultiResult2
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult2()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
}
Following are the steps describe you how LINQ to Stored proc works together.
Step 1-First create a table in your SQL server database-
I have created a table MyTable in the Northwind database.The table contains three feilds(MyID int,MyName Varchar,MyAddress varchar) MyID is a autogenerate number and primary key in this table.
Put some data in yout table
Step 2.Write the following stored proc in your database
-----------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableDelete] Script Date: 12/07/2009 00:08:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableDelete]
(
@MyID int
-- @MyName varchar(50),
-- @MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
DELETE from dbo.MyTable where MyID=@MyID
--SELECT MyID,MyName,MyAddress from dbo.MyTable
END
--select * from MyTable
-------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableInsert] Script Date: 12/07/2009 00:09:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableInsert]
(
@MyName varchar(50),
@MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO dbo.MyTable(MyName,MyAddress)VALUES(@MyName,@MyAddress)
END
------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelect] Script Date: 12/07/2009 00:10:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelect]
-- (
-- @MyID int,
-- @MyName varchar(50),
-- @MyAddress varchar(50)
-- )
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
END
--select * from MyTable
----------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelectMulti] Script Date: 12/07/2009 00:10:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelectMulti]
-- (
-- @MyID int
-- @MyName varchar(50),
-- @MyAddress varchar(50)
-- )
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=2
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=1
END
--select * from MyTable
----------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableSelectMultiWithOutputParam] Script Date: 12/07/2009 00:11:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableSelectMultiWithOutputParam]
(
@MyID int,
@MyName varchar(50) output
-- @MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
SELECT @MyName=(SELECT MyName from dbo.MyTable where MyID=@MyID)
END
--select * from MyTable
------------------------------------------------------------------------------------------------------------------------------
USE [Northwind]
GO
/****** Object: StoredProcedure [dbo].[spMyTableUpdate] Script Date: 12/07/2009 00:12:25 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[spMyTableUpdate]
(
@MyID int,
@MyName varchar(50),
@MyAddress varchar(50)
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE dbo.MyTable SET MyName=@MyName,MyAddress=@MyAddress
WHERE MyID=@MyID
END
Step 3.Create a new web site in .NET IDE
Step 4.Choose "Add New Item" on your App_Code folder
Step 5.Choose "LINQ to SQL Classes" in yourAdd New Item Dialog and put the file name "MyDataClasses.dbml".
Step 6.Open the MyDataClasses.dbml and modify the name "MyDataContext".Click on "Server Explorer" in MyDataClasses.dbml
Step7.In the Server Explorer click on "Connect to database" icon
Step 8.In "Add Connection" dialog put the server name,database name and required credentials
Step 9.Drag the requird Stored proc in your Method Pane
Step 10.If the Method Pane is not visible,right click on the designer and click on "Show Methods Pane".
Step 11.Now go to your Default.aspx page and create few buttons ,event and a gridview
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="grdData" runat="server">
</asp:GridView>
</div>
<asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" />
<asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update" />
<asp:Button ID="btnSelect" runat="server" OnClick="btnSelect_Click" Text="Select" />
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="Delete" />
<asp:Button ID="btnSelectMulti" runat="server" OnClick="btnSelectMulti_Click" Text="SelectMultipleDatatable" />
<asp:Button ID="btnSelectMultiWithOutputParam" runat="server" OnClick="btnSelectMultiWithOutputParam_Click"
Text="SelectMultipleWithOutputParameter" />
</form>
</body>
</html>
Step 12.In the Default.aspx.cs call the required stored procedure for Insert ,update ,select and Delete
MyDataContext db = new MyDataContext();
protected void btnInsert_Click(object sender, EventArgs e)
{
var q3 = db.spMyTableInsert("Indra", "Jadavpur");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var update = db.spMyTableUpdate(2,"Indra", "Jadavpur");
}
protected void btnSelect_Click(object sender, EventArgs e)
{
var Select2 = from o in db.spMyTableSelect()
where o.MyID <= 12 select new { o.MyID, o.MyName, o.MyAddress };
grdData.DataSource = Select2;
grdData.DataBind();
} protected void btnDelete_Click(object sender, EventArgs e)
{
var delete = db.spMyTableDelete(3);
}
Step 13.Now if you like to call a stored proc like dbo.spMyTableSelectMultiWithOutputParam which has a output param write teh follwoing code in your btnSelectMultiWithOutputParam click event
protected void btnSelectMultiWithOutputParam_Click(object sender, EventArgs e)
{
string strCustName = "";
var q2 = db.spMyTableSelectMultiWithOutputParam(1, ref strCustName);
Response.Write(strCustName.ToString());
grdData.DataSource = q2; grdData.DataBind();
}
The spMyTableSelectMultiWithOutputParam is like this
ALTER PROCEDURE dbo.spMyTableSelectMultiWithOutputParam
(
@MyID int, @MyName varchar(50) output
) AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable
SELECT @MyName=(SELECT MyName from dbo.MyTable where MyID=@MyID)
END Step
14.Now if you want to call a storedproc which is returning multiple select statement like spMyTableSelectMulti,do the following steps---
The stored proc is like this
ALTER PROCEDURE dbo.spMyTableSelectMulti
AS
BEGIN
SET NOCOUNT ON;
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=2
SELECT MyID,MyName,MyAddress from dbo.MyTable where MyID=1
END
Open the MyDataClassesDesigner.cs and comment the class spMyTableSelectMultiResult .
Then create a new class file clsMultiRecords.cs in App_code and create two partial class spMyTableSelectMultiResult and spMyTableSelectMultiResult2 First Class return the first SQL query and the second one return the second sql query.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Summary description for clsMultiRecords
/// </summary>
public class clsMultiRecords
{
public clsMultiRecords()
{
//
// TODO: Add constructor logic here
//
}
//[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((IMultipleResults)(result.ReturnValue));
//}
public partial class spMyTableSelectMultiResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
public partial class spMyTableSelectMultiResult2
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult2()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
}
Again open the DataClassesDesigner.cs and delete the follwoing portion
[Function(Name = "dbo.spMyTableSelectMulti")]
public ISingleResult
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult
}
and write the following code in place of that
[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
public IMultipleResults spMyTableSelectMulti()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}
This method will return the IMultipleResults instead of ISingleResult. Mind it,if you open the dbml(MyDataClasses.dbml not MyDataClasses.designer.cs) file and save/modify it, this above portion will be overridden by ISingleResult. Now go to the click event of btnSelectMulti and write the following code
protected void btnSelectMulti_Click(object sender, EventArgs e)
{
IMultipleResults results = new MyDataContext().spMyTableSelectMulti(); List
List
grdData.DataSource = result2;
grdData.DataBind();
}
Step 15.Now run your application ,you can now see the following output,click on different button to obeserve the operation
I am attaching the complete code for Default.aspx.cs ,MyDataContext class and clsMultiRecords.cs
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data.Linq;
public partial class _Default : System.Web.UI.Page
{
MyDataContext db = new MyDataContext();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnInsert_Click(object sender, EventArgs e)
{
var q3 = db.spMyTableInsert("Indra", "Jadavpur");
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var update = db.spMyTableUpdate(2,"Indra", "Jadavpur");
}
protected void btnSelect_Click(object sender, EventArgs e)
{
var Select2 = from o in db.spMyTableSelect()
where o.MyID <= 12
select new { o.MyID, o.MyName, o.MyAddress };
grdData.DataSource = Select2;
grdData.DataBind();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
var delete = db.spMyTableDelete(3);
}
protected void btnSelectMulti_Click(object sender, EventArgs e)
{
IMultipleResults results = new MyDataContext().spMyTableSelectMulti();
List<clsMultiRecords.spMyTableSelectMultiResult> result1 = results.GetResult<clsMultiRecords.spMyTableSelectMultiResult>().ToList();
List<clsMultiRecords.spMyTableSelectMultiResult2> result2 = results.GetResult<clsMultiRecords.spMyTableSelectMultiResult2>().ToList();
grdData.DataSource = result2;
grdData.DataBind();
}
protected void btnSelectMultiWithOutputParam_Click(object sender, EventArgs e)
{
string strCustName = "";
var q2 = db.spMyTableSelectMultiWithOutputParam(1, ref strCustName);
Response.Write(strCustName.ToString());
grdData.DataSource = q2;
grdData.DataBind();
}
}
MyDataContext class
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
[System.Data.Linq.Mapping.DatabaseAttribute(Name="Northwind")]
public partial class MyDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public MyDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public MyDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public MyDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
[Function(Name="dbo.spMyTableInsert")]
public int spMyTableInsert([Parameter(Name="MyName", DbType="VarChar(50)")] string myName, [Parameter(Name="MyAddress", DbType="VarChar(50)")] string myAddress)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myName, myAddress);
return ((int)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableUpdate")]
public int spMyTableUpdate([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID, [Parameter(Name="MyName", DbType="VarChar(50)")] string myName, [Parameter(Name="MyAddress", DbType="VarChar(50)")] string myAddress)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID, myName, myAddress);
return ((int)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableSelect")]
public ISingleResult<spMyTableSelectResult> spMyTableSelect()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((ISingleResult<spMyTableSelectResult>)(result.ReturnValue));
}
[Function(Name="dbo.spMyTableDelete")]
public int spMyTableDelete([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID);
return ((int)(result.ReturnValue));
}
//[Function(Name = "dbo.spMyTableSelectMulti")]
//public ISingleResult<spMyTableSelectMultiResult> spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((ISingleResult<spMyTableSelectMultiResult>)(result.ReturnValue));
//}
[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
public IMultipleResults spMyTableSelectMulti()
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
return ((IMultipleResults)(result.ReturnValue));
}
//[Function(Name = "dbo.spMyTableSelectMulti")]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return (IMultipleResults)(result.ReturnValue);
//}
[Function(Name="dbo.spMyTableSelectMultiWithOutputParam")]
public ISingleResult<spMyTableSelectMultiWithOutputParamResult> spMyTableSelectMultiWithOutputParam([Parameter(Name="MyID", DbType="Int")] System.Nullable<int> myID, [Parameter(Name="MyName", DbType="VarChar(50)")] ref string myName)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), myID, myName);
myName = ((string)(result.GetParameterValue(1)));
return ((ISingleResult<spMyTableSelectMultiWithOutputParamResult>)(result.ReturnValue));
}
}
public partial class spMyTableSelectResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectResult()
{
}
[Column(Storage="_MyID", DbType="Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage="_MyName", DbType="VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage="_MyAddress", DbType="VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
//public partial class spMyTableSelectMultiResult
//{
// private int _MyID;
// private string _MyName;
// private string _MyAddress;
// public spMyTableSelectMultiResult()
// {
// }
// [Column(Storage="_MyID", DbType="Int NOT NULL")]
// public int MyID
// {
// get
// {
// return this._MyID;
// }
// set
// {
// if ((this._MyID != value))
// {
// this._MyID = value;
// }
// }
// }
// [Column(Storage="_MyName", DbType="VarChar(50)")]
// public string MyName
// {
// get
// {
// return this._MyName;
// }
// set
// {
// if ((this._MyName != value))
// {
// this._MyName = value;
// }
// }
// }
// [Column(Storage="_MyAddress", DbType="VarChar(50)")]
// public string MyAddress
// {
// get
// {
// return this._MyAddress;
// }
// set
// {
// if ((this._MyAddress != value))
// {
// this._MyAddress = value;
// }
// }
// }
//}
public partial class spMyTableSelectMultiWithOutputParamResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiWithOutputParamResult()
{
}
[Column(Storage="_MyID", DbType="Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage="_MyName", DbType="VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage="_MyAddress", DbType="VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
#pragma warning restore 1591
clsMultiRecords.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>
/// Summary description for clsMultiRecords
/// </summary>
public class clsMultiRecords
{
public clsMultiRecords()
{
//
// TODO: Add constructor logic here
//
}
//[Function(Name = "dbo.spMyTableSelectMulti"), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult)), ResultType(typeof(clsMultiRecords.spMyTableSelectMultiResult2))]
//public IMultipleResults spMyTableSelectMulti()
//{
// IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
// return ((IMultipleResults)(result.ReturnValue));
//}
public partial class spMyTableSelectMultiResult
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
public partial class spMyTableSelectMultiResult2
{
private int _MyID;
private string _MyName;
private string _MyAddress;
public spMyTableSelectMultiResult2()
{
}
[Column(Storage = "_MyID", DbType = "Int NOT NULL")]
public int MyID
{
get
{
return this._MyID;
}
set
{
if ((this._MyID != value))
{
this._MyID = value;
}
}
}
[Column(Storage = "_MyName", DbType = "VarChar(50)")]
public string MyName
{
get
{
return this._MyName;
}
set
{
if ((this._MyName != value))
{
this._MyName = value;
}
}
}
[Column(Storage = "_MyAddress", DbType = "VarChar(50)")]
public string MyAddress
{
get
{
return this._MyAddress;
}
set
{
if ((this._MyAddress != value))
{
this._MyAddress = value;
}
}
}
}
}
2009-12-14
Estimation using Fuction Point Analysis-Phase Considaration and cost calculation(Part 6)
We generally distribute the phase of a project in the following manner after getting the total Man Days
And the we can asign resources in the following manner ,it can vary according to your company strength or company policy.this is just a sample
Now you can calculate your total cost for your project depending on the salary of your team member and other cost.
And the we can asign resources in the following manner ,it can vary according to your company strength or company policy.this is just a sample
Now you can calculate your total cost for your project depending on the salary of your team member and other cost.
Estimation using Fuction Point Analysis-Productivity Factor(Part 5)
Estimation using Fuction Point Analysis-GSC(Part 4)
2009-12-04
Estimation using Fuction Point Analysis-EIF,ILF(Part 3)
What is External Interface File(EIF):
EIF is a user-indentifiable logically related data which is utilized by the applicatin but maintained by some other application.They are not maintained by the application.
For example,if you are using credit card information,or using some kind of payment gateway that are only referencing and application don't have the control directly,then this file ise a EIF.
Complexity Table of EIF:
It depends on two things:
-Record Element type(RET):They are logical sub groupings of DET from user view point.If there is no logical grouping of data then we consider it as one RET. In the following context there are several phone number for a customer,but they are logically grouping.
-Data Element Type(DET):Counting of DET doesn't change for EIF,EI,EO,EQ .
EIF complexity table:
What is Internal Logical File(ILF):
An ILF is a user identifiable group of logically related data maintained by the application.
Application have directly control on ILF.
Identify ILF's:
Stored internal to the application
Maintained through a standarized process of application.
User identified.
Temp file are not count as ILF's.
In the above context if your client thing that there is only one phone number for a customer but still you have maintained it in two tables for scale up your application,then you have to count 1 ILF ,but if a customer has multiple phone number and you require two table(master & details) then the ILF should be 2.
Complexity of ILF: It depends on two things:
-Record Element type(RET)
-Data Element Type(DET)
Complexity Table of ILF:
EIF is a user-indentifiable logically related data which is utilized by the applicatin but maintained by some other application.They are not maintained by the application.
For example,if you are using credit card information,or using some kind of payment gateway that are only referencing and application don't have the control directly,then this file ise a EIF.
Complexity Table of EIF:
It depends on two things:
-Record Element type(RET):They are logical sub groupings of DET from user view point.If there is no logical grouping of data then we consider it as one RET. In the following context there are several phone number for a customer,but they are logically grouping.
-Data Element Type(DET):Counting of DET doesn't change for EIF,EI,EO,EQ .
EIF complexity table:
What is Internal Logical File(ILF):
An ILF is a user identifiable group of logically related data maintained by the application.
Application have directly control on ILF.
Identify ILF's:
Stored internal to the application
Maintained through a standarized process of application.
User identified.
Temp file are not count as ILF's.
In the above context if your client thing that there is only one phone number for a customer but still you have maintained it in two tables for scale up your application,then you have to count 1 ILF ,but if a customer has multiple phone number and you require two table(master & details) then the ILF should be 2.
Complexity of ILF: It depends on two things:
-Record Element type(RET)
-Data Element Type(DET)
Complexity Table of ILF:
2009-12-03
Estimation using Fuction Point Analysis-EO,EQ(Part 2)
What is External Output(EO)?
External Output(EO)-EO's are functions which manipulate data and present to the user.
Manipulation means derived and calculated informaton.
Some of real time EO examples are(becuse it need complex query along with the calculation) -
-Balance sheet report
-Customer monthly statement
-Complex graphical charts like bar chart ,pie chart etc.
If the same EO data is produced on two different media output should be counted as two EO's.In short if the same data is sent on a web page and also on a mobile will be counted as 2 EO's.
Graphical output of data in Pie chart ,bar chart etc should be counted as EO's.
If a report is generated by report generator it should be counted as EO.One EI should be counted for each report command like search ,sort ,merge etc generated by report generator.
What are not EO's?
ADHOC reporting where the end user can fire SQL and generate report is not a EO.For example ,if you have made a simple query window where the end user can fire and get the data are not EO.
Two report showing the different data with same processing logic (suppose one query output is ascending order and another is descending order)should be counted as on EO
Complexity of EO:
Like EI,Complexity of EO is depends on File type reference(FTR) and Data element type(DET)
DET are fields and attributes.
DET should be unique and user recognizable.
Count DET for each parameter in the report.Suppose you are generating reports based on the user input i.e Cust ID and Cust Name,then the DTE is 2
Count DET for each numerical value in a graphical output.Suppose you are showing graph which showing percentage value or other numeric value,you need to count the DET.
Count DET for summary and totalling fields.Suppose yoy are showing each month summery profit and total year profit ,then you should count 1 DET.
Complexity Table for EO:
Like EI,you can determine the complexity of EO from the Complexity table of EO as follows-
What is External Quaries(EQ):
EQ is a unique request for retrieving data.
EQ does not update any ILF's or EIF's.
EQ doesnot contain derived data it simply retrieves the information where EO retrives complex calculated data.Suppose in customer screen ,customer dropdown is EO because it direct fetch data from Customer Master table.
Example of EQ:
Dynamic dropdown or list display
Simple reports displayed from a single table without data manipulation
Section of data retrieval based on input.
Different graphical display request by a user should be counted as EQ.
Help functionality which displays help text or field sensitive help will be counted as one EQ Perscreen.Suppose you have a screen where F1 key press shows the help,then the EQ will be 1 for that.
Complexity of EO: Like EI,EO,Complexity of EQ is depends on File type reference(FTR) and Data element type(DET)
Complexity Table for EQ:
But remember for complex Query ,calculated output you should consider EO and for simple query you should consider EQ(EQ just go for one ILF and displays information)
Estimation using Fuction Point Analysis-EI(Part 1)
Fuction point is a unit of measurefor software size based on user requirements(not the internal process i.e we should not consider the internal complexity or workflow,only consider the user requirement).It was developed by Mr.Allan Albrecht at IBM in the late 1970s,as an alternative of line of code.(line of code has some limitations like its vary language to language and its difficult to predict).
Software measure is a numerical value assigned to a software project depending on the complexity of project.The complexity of software can be known from "Data Collected" and "ClientArtifacts".It can be-
1)Function Points
2)Use case points
3)Lines of code
and convert to Man days,Man month or Man hours numerical values.
The objective of this tutorial is how to calculate this Function point and arrive to Man days so that you can give a proposal to a client.
First see what are the different operations a user does with an application-
The major element of Function point analysis is Application boundaries.There are two Application boundaries-
-1.Internal:Data which is maintained and directly controlled by application(ILF)
-2.External:When data is referenced to external entities(EIF)
The more you have external application boundary the more complexity.So first differentiate the application boundary before FPA.
Now come to the rest of the elements like EI,EO,EQ,EIF and ILF etc.
EI(External Input)-EI moves the data in to the application from external app boundary to internal boundary.EI mainly updates ILF information.
For every add/update and delete count one EI
Every input screen is not a EI.i.e Query screen ,login screen,menus reports screen cannot be counted as EI even there is a user input.
Process that maintain ILF like windows process or batch process that update database should be counted as EI.
EI has two attributes which basically define the complexity of EI
-1.File type reference(FTR):
FTR is a file or data referenced by EI.
Count 1 FTR for every ILF maintained.
Count 1 FTR for every ILF referenced.
Count 1 FTR for every EIF referenced.
-2.Data element type(DET):
DET are fields and attributes.In the above customer screen Customer code,Customer Name are fields or attributes ,so these are DETs.
DET should be unique and user recognizable.If the customer screen comes again for another operation from another menu we should not count DET.
Foreign keys are also DET's.Suppose customer ID is foreign key of address table ,then this foreign key should be counted as DET.
Auto generated fields are also counted as DET as they are maintained in the ILF.Because we have to write seperate logic to create autogenerate numbers.
Duplicate fields populated by the same user input should be counted as one DET.
Error message are counted as DET.
So In this example there is 12 DET and 3 FTR,So from EI rating table 6 is a complexity level of customer screen
If we consider, 3 is a simple,4 is a medium and 6 is a complex,then from EI complexity table we can get the complexity value "complex" for this Customer screen
Software measure is a numerical value assigned to a software project depending on the complexity of project.The complexity of software can be known from "Data Collected" and "ClientArtifacts".It can be-
1)Function Points
2)Use case points
3)Lines of code
and convert to Man days,Man month or Man hours numerical values.
The objective of this tutorial is how to calculate this Function point and arrive to Man days so that you can give a proposal to a client.
First see what are the different operations a user does with an application-
The major element of Function point analysis is Application boundaries.There are two Application boundaries-
-1.Internal:Data which is maintained and directly controlled by application(ILF)
-2.External:When data is referenced to external entities(EIF)
The more you have external application boundary the more complexity.So first differentiate the application boundary before FPA.
Now come to the rest of the elements like EI,EO,EQ,EIF and ILF etc.
EI(External Input)-EI moves the data in to the application from external app boundary to internal boundary.EI mainly updates ILF information.
For every add/update and delete count one EI
Every input screen is not a EI.i.e Query screen ,login screen,menus reports screen cannot be counted as EI even there is a user input.
Process that maintain ILF like windows process or batch process that update database should be counted as EI.
EI has two attributes which basically define the complexity of EI
-1.File type reference(FTR):
FTR is a file or data referenced by EI.
Count 1 FTR for every ILF maintained.
Count 1 FTR for every ILF referenced.
Count 1 FTR for every EIF referenced.
-2.Data element type(DET):
DET are fields and attributes.In the above customer screen Customer code,Customer Name are fields or attributes ,so these are DETs.
DET should be unique and user recognizable.If the customer screen comes again for another operation from another menu we should not count DET.
Foreign keys are also DET's.Suppose customer ID is foreign key of address table ,then this foreign key should be counted as DET.
Auto generated fields are also counted as DET as they are maintained in the ILF.Because we have to write seperate logic to create autogenerate numbers.
Duplicate fields populated by the same user input should be counted as one DET.
Error message are counted as DET.
So In this example there is 12 DET and 3 FTR,So from EI rating table 6 is a complexity level of customer screen
If we consider, 3 is a simple,4 is a medium and 6 is a complex,then from EI complexity table we can get the complexity value "complex" for this Customer screen
Subscribe to:
Posts (Atom)