• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
PowerCoder
博客园    首页    新随笔    联系   管理    订阅  订阅
上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 68 下一页
2018年10月17日
EF Core 2.0中Transaction事务会对DbContext底层创建和关闭数据库连接的行为有所影响
摘要: 数据库 我们先在SQL Server数据库中建立一个Book表: 然后插入如下数据: 查询Book表的数据,如下图所示: 现在我们使用EF Core将Book表映射到.NET Core控制台项目中的Book实体上,Book实体如下所示: 不使用事务 然后我们在.NET Core控制台项目Progra 阅读全文
posted @ 2018-10-17 11:25 PowerCoder 阅读(2030) 评论(0) 推荐(2)
Parallel.ForEach使用示例
摘要: 新建一个.NET Core控制台程序,代码如下: 执行后结果如下: 因为Parallel.ForEach为并行执行,所以再次执行时6个数字出现的顺序可能会不一样。 阅读全文
posted @ 2018-10-17 10:17 PowerCoder 阅读(4077) 评论(0) 推荐(0)
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)
上一页 1 ··· 38 39 40 41 42 43 44 45 46 ··· 68 下一页
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3