实体框架,找出存储过程是否成功运行

时间:2013-02-19 11:13:45

标签: entity-framework

我有一个这样的存储过程:

@uName nvarchar(20),
@password nvarchar(50)
AS
IF NOT EXISTS(SELECT UserName FROM Members WHERE UserName = @uName)
BEGIN
    INSERT INTO Members(UserName, Password) VALUES (@uName, @password)
END

此存储过程映射到我的Members实体,并由EF隐式调用。

如何确定是否插入了行?

using (var context = new BlogEntities())
{    
    var member = new Member()
    {
        UserName = "Blah",
        Password = "Blah"
    };

    int affected = context.SaveChanges();
}

变量affected始终返回1

0 个答案:

没有答案