我正在使用代码优先的方法在我的应用程序中。我已经使用这种方法生成了实体(表)。现在我还想通过代码创建一个存储过程。有人能指导一下我吗?我尝试了迁移选项,但它失败了。
我正在使用Entity Framework Code First方法。使用这种方法,我已经创建了客户和其他一些实体。
现在我想使用上下文类创建一个存储过程“GetCustomers”,并传递参数,并在集合中获得结果集。
它必须返回以下2个集合:
create procedure getcustomer @name nvarchar(max),@zipcode int
as
select id,name,zipcode from Customer where name like (@name );
select id,name,zipcode from Customer where zipcode =@zipcode
我想使用上下文类创建存储过程“GetCustomers”,而不是手动在数据库中执行。我需要实现以下结果:
1.只传递名称参数并返回第一个集合。
2.只传递邮政编码参数并返回第二个集合。
3.使用合并将第1和第2个结果集合并成单个集合。
我正在使用Entity Framework Code First方法。使用这种方法,我已经创建了客户和其他一些实体。
现在我想使用上下文类创建一个存储过程“GetCustomers”,并传递参数,并在集合中获得结果集。
它必须返回以下2个集合:
create procedure getcustomer @name nvarchar(max),@zipcode int
as
select id,name,zipcode from Customer where name like (@name );
select id,name,zipcode from Customer where zipcode =@zipcode
我想使用上下文类创建存储过程“GetCustomers”,而不是手动在数据库中执行。我需要实现以下结果:
1.只传递名称参数并返回第一个集合。
2.只传递邮政编码参数并返回第二个集合。
3.使用合并将第1和第2个结果集合并成单个集合。
{
modelBuilder.Entity<yourEntity>().MapToStoredProcedures();
}请参阅此链接:https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/fluent/cud-stored-procedures - MarchalPT