将自定义类型的存储过程作为参数附加到EDMX

时间:2015-04-09 14:35:13

标签: c# entity-framework sql-server-2008 entity-framework-6

我使用Custom TYPE参数创建了一个样本存储过程 它在SQL中完美执行,但我无法将其附加到EDMX(EF 6)。

CREATE TYPE dbo.ArrayINT
AS TABLE
(
  Value INT
);
GO

CREATE PROCEDURE DeleteItems
(
@IDs dbo.ArrayINT READONLY
) AS
BEGIN

//...Logic to delete

END

1 个答案:

答案 0 :(得分:0)

没有直接的方法可以做到这一点。但您可以使用ExecuteSqlCommanddatatable

来解决
var context = new TSQL2012Entities();

var table = new DataTable();
table.Columns.Add("SomeColumn1");
table.Columns.Add("SomeColumn2");
table.Rows.Add(someValue11, someValue21);
table.Rows.Add(someValue21, someValue22);

var param = new SqlParameter("param1", SqlDbType.Structured);
param.Value = table;
param.TypeName = "[dbo].[YourTableType]";

string command = "EXEC spProcName @param1";
context.Database.ExecuteSqlCommand(command, param);