I want to use stored procedure with code first and I studied
http://msdn.microsoft.com/en-gb/data/dn468673 . It seems that code first creates a default stored procedure and the developers must change the stored procedure in the DB on each recreation of DB! There is only capabilities to change parameter names not
body of stored procedure. at some part SQL code and C# code is used together without any comment between! I thought SQL code is added to the model!
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
public string Url { get; set; }
[Timestamp]
public byte[] Timestamp { get; set; }
}
CREATE PROCEDURE [dbo].[Blog_Update]
@BlogId int,
@Name nvarchar(max),
@Url nvarchar(max),
@Timestamp_Original rowversion
AS
UPDATE [dbo].[Blogs]
SET [Name] = @Name, [Url] = @Url
WHERE BlogId = @BlogId AND [Timestamp] = @Timestamp_Original
Can anyone make it clear for me what capabilities code first have in terms of stored procedure.
It's generally supposed that when First Code is used, everything that needed to create a database is in code. What I understand from my link is that the body of stored procedure is not defined in code but a default stored procedure is create for each operation
and the developer must change it each time the database recreated. I think this is in direct contradiction with code first supposition. Each stored procedure detail must be part of the model. Can you please tell me if there is no misunderstanding?
Member
130 Points
233 Posts
Stored procedure ambiguity in code first
Sep 28, 2014 04:22 AM|IranianCuriousBoy|LINK
Hi
I want to use stored procedure with code first and I studied http://msdn.microsoft.com/en-gb/data/dn468673 . It seems that code first creates a default stored procedure and the developers must change the stored procedure in the DB on each recreation of DB! There is only capabilities to change parameter names not body of stored procedure. at some part SQL code and C# code is used together without any comment between! I thought SQL code is added to the model!
Can anyone make it clear for me what capabilities code first have in terms of stored procedure.
Thanks
All-Star
16806 Points
2777 Posts
Microsoft
Re: Stored procedure ambiguity in code first
Sep 28, 2014 11:29 PM|Kevin Shen - MSFT|LINK
Hi IranianCuriousBoy,
According to the article you post ,You can change the name of one or more stored procedures.
Based on my understanding, for update/delete single table, the body in the stored procedure are almost the same.
You don't need to change the body.
If you define your own stored procedure, you can use ExecuteStoreQuery and ExecuteStoreCommand to call stored procedure.
you can refer to the tutorial in the link below:
http://www.codeproject.com/Articles/522611/Entity-Framework-CRUD-Operations-Using-Stored-Proc
Best Regards,
Kevin Shen.
Member
130 Points
233 Posts
Re: Stored procedure ambiguity in code first
Sep 29, 2014 07:57 AM|IranianCuriousBoy|LINK
Hi Kevin
It's generally supposed that when First Code is used, everything that needed to create a database is in code. What I understand from my link is that the body of stored procedure is not defined in code but a default stored procedure is create for each operation and the developer must change it each time the database recreated. I think this is in direct contradiction with code first supposition. Each stored procedure detail must be part of the model. Can you please tell me if there is no misunderstanding?
The link you provided is not code first
Best Regards