[英]Is it possible to generate basic CRUD stored procedures on database with code-first entity framework?
I have searched but couldnt find any useful thing about generating automatically basic CRUD stored procedures when creating the database in code first approach. 我已经搜索过,但是找不到以代码优先方式创建数据库时自动生成基本CRUD存储过程的任何有用的信息。 I am wondering is there a way to do this simply or i should create all the CRUD stored procedure by old fashion?
我想知道是否有一种方法可以简单地做到这一点,或者我应该以旧方式创建所有CRUD存储过程?
It is indeed possible to use Migrations with a Code First Database to generate stored procedures for CRUD operations in Entity Framework 6 and beyond. 实际上,可以将“迁移”与“代码优先”数据库一起使用,以生成用于实体框架6及更高版本中CRUD操作的存储过程 。 Note that this is not possible in this manner with Entity Framework 5 and earlier, though you could still use raw SQL calls.
请注意,尽管您仍然可以使用原始SQL调用,但对于Entity Framework 5和更早版本,这是不可能的。
DbSet
for the entity to your DbContext
class. DbSet
添加到DbContext
类。 OnModelCreating
method of the DbContext
to add the following entry: modelBuilder.Entity<SomeEntity>().MapToStoredProcedures();
OnModelCreating
所述的方法DbContext
添加以下条目: modelBuilder.Entity<SomeEntity>().MapToStoredProcedures();
. add-migration
, ie add-migration SPGenerate
. add-migration
生成一个新add-migration
,即add-migration SPGenerate
。 Up
method of your migration to tweak the Stored Procedures to your liking. Up
方法,以根据自己的喜好调整存储过程。 update-database
in the Package Manager Console. update-database
,将迁移提交到数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.