PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 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?

PrepAway - Latest Free Exam Questions & Answers

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())
{
CtojectParameter id = null;
context.InsertDepartment(“Department 1”, id);
Console.WriteLine(id.Value);
}

D.
using (SchoolEntities context = new SchoolEntities())
{

var id = new OtajectParameter(“ID”, null));
context.InsertDepartment(“Department 1”, id);
Console.WriteLlne(id.Value);
}

Explanation:
http://blogs.microsoft.co.il/blogs/gilf/archive/2010/05/09/how-to-retrieve-storedprocedure-output-parametersin-entity-framework.aspx


Leave a Reply