You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 to develop an application that connects to a Microsoft SQL Server 2008 database.
You use the ADO.NET Entity Framework Designer to model entities. You add the following stored procedure to the database, and you add a function import to the model.
CREATE PROCEDURE [dbo].[InsertDepartment]
@Name nvarchar(50),
@ID int NULL OUTPUT
AS
INSERT INTO Department (Name) VALUES (@Name)
SELECT @ID = SCOPE_IDENTITY()
You need to insert a new department and display the generated ID. Which code segment should you use?
A.
using (SchoolEntities context = new SchoolEntities())
{
var id = new ObjectParameter(“ID”, typeof(int));
context.InsertDepartment(“Department 1”, id);
Console.WriteLine(id.Value);
}
B.
using (SchoolEntities context = new SchoolEntities())
{
var id = context.InsertDepartment(“Department 1”, null);
Console.WriteLine(id);
}
C.
using (SchoolEntities context = new SchoolEntities())
{
ObjectParameter id = null;
context.InsertDepartment(“Department 1”, id);
Console.WriteLine(id.Value);
}
D.
using (SchoolEntities context = new SchoolEntities())
{
var id = new ObjectParameter(“ID”, null));
context.InsertDepartment(“Department 1”, id);
Console.WriteLine(id.Value);
}
Explanation:
http://blogs.microsoft.co.il/blogs/gilf/archive/2010/05/09/how-to-retrieve-stored-procedure-output-parameters-in-entity-framework.aspx