c# - 在 EF Core Fluent 配置中使用 SqlServer HASHBYTES
问题描述
是否可以使用 HASHBYTES 作为 Entity Framework Core 中列的默认值?在插入/更新时,我想在同一个表的不同列中获取值的哈希值。
在我的配置文件中,我有这样的东西:
builder.Property( a => a.File )
.IsRequired();
builder.Property(a => a.Hash)
.HasDefaultValueSql( "HASHBYTES('SHA2_256', ??? )" )
但我不知道如何引用“文件”列。如何引用“文件”?
我试过了:
builder.Property( a => a.Hash )
.HasDefaultValueSql( "HASHBYTES('SHA2_256', [File] )" );
但结果是
The name "File" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
解决方案
推荐阅读
- android - 我可以删除哪些文件并且该项目仍然可以工作
- c++ - 使用带有 max_element 的 lamda 函数编译错误
- aframe - 如何从另一个文件运行 A-Frame 代码以防止混乱?
- swift - queryOrdered 并不总是以正确的顺序返回 tableViewCell 上的数据
- python-3.x - Pygit2:在如何处理所有 repo 分支中的所有提交方面需要帮助
- css - 与 Internet Explorer 兼容的 CSS 过滤器生成器
- java - 通过读取其索引进行整数操作
- maven - 如何在没有第三方服务的情况下集成 Maven 和 Github?
- r - 按顺序生成排列 - R
- powershell - 提取两个方括号之间的值