好的,所以在实体框架 6 中,我会在一个语句中生成密钥和属性数据库:
modelBuilder.Entity<Function>()
.HasKey(x => x.Id)
.Property(x => x.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
Run Code Online (Sandbox Code Playgroud)
在实体框架核心 (7) 中,这不起作用:
modelBuilder.Entity<Function>()
.HasKey(x => x.Id)
.Property(x => x.Id)
.ValueGeneratedNever();
Run Code Online (Sandbox Code Playgroud)
错误:“‘KeyBuilder’不包含‘Property’的定义,并且没有接受‘KeyBuilder’类型的第一个参数的扩展方法‘Property’”:
这是否必须是如下两个单独的语句,或者有没有办法像在 EF6 中那样将其合并在一起?
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Function>()
.HasKey(x => x.Id);
modelBuilder.Entity<Function>()
.Property(x => x.Id)
.ValueGeneratedNever();
}
Run Code Online (Sandbox Code Playgroud) c# entity-framework fluent fluent-entity-framework entity-framework-core
I'm trying to translate the following SQL in to an EF Core query and I'm getting warnings that GroupBy and Sum will be evaluated locally. Is there anyway currently to write this that it will fully translate to SQL?
SELECT UserId, ST.StatusId, SUM(DATEDIFF(MINUTE, StartDate, ISNULL(EndDate,GETDATE()))) AS Time
FROM StatusTransaction ST
WHERE
TeamManagerId = 1
AND StartDate >= N'01-01-2019'
AND ISNULL(EndDate,GETDATE()) <= N'01-02-2019'
GROUP BY UserId, ST.StatusId
ORDER BY UserId
Run Code Online (Sandbox Code Playgroud)
And these are the EF queries I've used:
var efFunction = …Run Code Online (Sandbox Code Playgroud)