Articles → ADO.NET → Call stored procedure using entity framework

Call stored procedure using entity framework
















Click to Enlarge



CREATE VIEW vw_GetEmployeeData AS 
SELECT 
  e.EmployeeId, 
  e.EmployeeName, 
  d.DepartmentName 
FROM 
  Employee e 
  INNER JOIN Department d ON e.DepartmentId = d.DepartmentId





Click to Enlarge






Click to Enlarge



-- Procedure to insert value in attribute table
Create Proc InsertAttribute @Attribute VARCHAR(50) As Insert into Attribute 
values 
  (@Attribute) -- Procedure to get attribute based on attribute
  CREATE PROC GetAttribute @AttributeId int As 
Select 
  * 
from 
  Attribute 
where 
  AttributeId = @AttributeId -- Procedure to check if the attribute exists
  ALTER PROC IsAttributeExists @AttributeId int As IF EXISTS(
    Select 
      * 
    from 
      Attribute 
    where 
      AttributeId = @AttributeId
  ) 
SELECT 
  'EXIST' ELSE 
SELECT 
  'NOTEXIST'







Click to Enlarge




Click to Enlarge




Click to Enlarge












Click to Enlarge




Click to Enlarge





using(ABCEntities context = new ABCEntities()) {
	//  Proc 1
	context.InsertAttribute("Name");

	//Proc 2
	string status = context.IsAttributeExists(1).First();
	Console.WriteLine(string.Format("status = {0}", status));
	// Proc 3
	Attribute attr = context.GetAttribute(1).First();

	Console.WriteLine(string.Format("Attributeid= {0}{1}AttributeName= {2}", attr.AttributeId, Environment.NewLine, attr.AttributeName));

	Console.ReadLine();
}



Output



Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, January 08, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250