1,利用Linq to SQL框架选择相关的数据实体,在"配置行为"对话框中调用相关的存储过程.可以非常方便的实现使用存储过程更新数据.

方案: ①通过添加数据验证以及数据访问方法来实现数据访问层.

②通过Linq来使用数据访问层

③在数据实体类的属性窗口中,分别设置插入和更新属性

④在"配置行为"对话框中分别实现插入和更新的存储过程

1.1添加数据验证规则:

public partial class PlayerInfoVO {
    partial void OnNameChanging(string value) {
        Regex myName = new Regex(@"^[a-zA-Z0-9_]{3,16}$");
        if (myName.IsMatch(value) == false) {
            throw new ArgumentException("无效的名字");
        }
    }
}

1.2创建数据访问方法

public partial class MYDBDataContext {
    public myLevel GetMyLevel(int id) {
        return this.myLevel.Single(c => c.id == id);
    }
}

注意此段代码 , 要在 dbml 中写

1.3使用数据访问层

1.4增加数据

1,写一个Proc名为InsertPlayer 设@OK为OUTPUT型,in为输入类型

2,Linq存储过程(二)

弹出"配置行为"

Linq存储过程(二)


转载于:https://blog.51cto.com/aonaufly/1315646

相关文章:

  • 2022-12-23
  • 2021-05-11
  • 2021-09-30
  • 2021-12-06
  • 2021-12-25
  • 2021-10-01
  • 2021-12-01
  • 2021-07-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案