• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅
2018年10月16日
Entity Framework中DbContext结合TransactionScope提交事务的正确方式
摘要: 问: I would like know what is the best possible way to implement transactions with DBContext. In particular, 答: Example: 从上面的代码我们可以看出来在Entity Framework 阅读全文
posted @ 2018-10-16 23:53 PowerCoder 阅读(810) 评论(0) 推荐(0)
SQL Server中事务transaction如果没写在try catch中,就算中间语句报错还是会提交
摘要: 假如我们数据库中有两张表Person和Book Person表: Book表: 可以看到Person表和Book表是一对多关系,一个Person可以有多个Book,所以Book表的PersonCode列是外键,指向Person表的Code列,并为强制约束,也就是说Book表的PersonCode列的 阅读全文
posted @ 2018-10-16 21:02 PowerCoder 阅读(1910) 评论(0) 推荐(0)
EF Core中Key属性相同的实体只能被跟踪(track)一次
摘要: 在EF Core的DbContext中,我们可以通过DbContext或DbSet的Attach方法,来让DbContext上下文来跟踪(track)一个实体对象,假设现在我们有User实体对象,其UserCode为Key属性: 现在我们使用DbSet的Attach方法将两个UserCode都为"U 阅读全文
posted @ 2018-10-16 18:32 PowerCoder 阅读(12020) 评论(0) 推荐(0)
在Entity framework中使用事务
摘要: 默认情况下,当EF调用SaveChanges()时,会把生成的所有SQL命令“包”到一个“事务(transaction)”中,只要有一个数据更新操作失败,整个事务将回滚。在多数情况下,如果你总在数据更新操作代码中使用一个而不是多个DbContext对象,并且只是在最后调用一次SaveChanges( 阅读全文
posted @ 2018-10-16 18:04 PowerCoder 阅读(2268) 评论(0) 推荐(1)
SQL Server 2016 中有外键的表无法被Truncate,只能被Delete
摘要: 问: I get the following message even when the table that references it is empty: "Cannot truncate table 'dbo.Link' because it is being referenced by a 阅读全文
posted @ 2018-10-16 15:58 PowerCoder 阅读(844) 评论(0) 推荐(0)
C#中Lambda表达式类型Expression不接受lambda函数
摘要: 在EF Core中我们经常会用System.Linq.Expressions系统命名空间的Expression<TDelegate>类型来作为EF Core的查询条件,比如: using EFLambdaExpression.Entities; using System; using System. 阅读全文
posted @ 2018-10-16 11:24 PowerCoder 阅读(3306) 评论(0) 推荐(0)
Non-Nullable Types vs C#: Fixing the Billion Dollar Mistake (转载)
摘要: One of the top suggestions (currently #15 on uservoice) for improving C# is the addition of non-nullable reference types. This is not surprising, cons 阅读全文
posted @ 2018-10-16 10:34 PowerCoder 阅读(385) 评论(0) 推荐(0)
C# 6.0 的?.运算符
摘要: What is it? Here’s the scenario Consider getting the grandchild of a parent object like this: var g1 = parent.child.child.child; 很明显parent类里面有一个child类 阅读全文
posted @ 2018-10-16 10:10 PowerCoder 阅读(364) 评论(0) 推荐(0)
在SQL Server中用好模糊查询指令LIKE (转载)
摘要: like在sql中的使用:在SQL Server中用好模糊查询指令LIKE;查询是SQL Server中重要的功能,而在查询中将Like用上,可以搜索到一些意想不到的结果和效果,like的神奇 一、一般搜索条件中用Like之处在于其提供的模糊查询功能,通过与它相匹配的四大类通配符,like放在条件中 阅读全文
posted @ 2018-10-16 01:00 PowerCoder 阅读(4221) 评论(0) 推荐(0)
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3