在实体框架中使用相同的存储过程进行插入和更新 [英] Using Same Stored Procedure for Both Insert and Update in Entity Framework

查看:99
本文介绍了在实体框架中使用相同的存储过程进行插入和更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程同时执行插入和更新(如果id == 0则是插入,否则更新)。我很乐意在Entity Framework中使用这种插入和更新方法,但这看起来不太可行。我正确的是,我必须将方法分成两个不同的存储过程,还是有一种方法?

解决方案

我将首先尝试,在XML编辑器中打开EDMX,并在StorageModel元素中找到sproc(Function),复制它,给它一个新的名称。



然后,您可以将一个实际存储过程映射一次,因为插入修改功能一次作为更新修改功能。



我没有实际尝试过,但我可以不明白为什么这不行。



希望这有帮助



亚历克斯詹姆斯,微软计划经理


I have a stored procedure that does both the insert and the update in one fell swoop (if the id == 0 then it's an insert, otherwise, update). I'd love to use this for both the insert and the update methods in Entity Framework, but this isn't looking feasible. Am I correct that I'll have to split the methods into two different stored procedures, or is there a way around this?

解决方案

On way I would try first, is opening the EDMX in the XML editor and finding the sproc (Function) in the StorageModel element, copy it, giving it a new name.

Then you can map one actual stored procedure twice once as the Insert Modification function once as the Update Modification function.

I haven't actually tried this, but I can't see why this won't work.

Hope this helps

Alex James, Program Manager, Microsoft

这篇关于在实体框架中使用相同的存储过程进行插入和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆