Код: Выделить всё
select foo.*
, (case when hst.Id is not null and foo.OtherColumn = 1 then 42 else null end)
as Bar
from FooEntities foo
left join
FooEntities for system_time all hst on hst.Id = foo.Id
and hst.OtherColumn = 999
Код: Выделить всё
FooEntityЯ использую подход на основе модели (сущности, генерируемые из БД), поэтому начните с:
Код: Выделить всё
// generated from DB
public partial class FooEntity
{
public int Id { get; set; }
public byte OtherColumn { get; set; }
... other properties...
}
public partial class MyDbContext : DbContext
{
public virtual DbSet FooEntities { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity(... mapping configuration...);
}
}
Код: Выделить всё
// manually created
public partial class FooEntity
{
public int? Bar { get; set; }
}
public partial class MyDbContext
{
partial void OnModelCreatingPartial(ModelBuilder modelBuilder)
{
modelBuilder.Entity(entity => entity.Ignore(e => e.Bar));
}
}
Код: Выделить всё
public IQueryable QueryFoosWithBar(IQueryable foos)
{
return foos
.GroupJoin(
_dbContext.Set().TemporalAll()
.Where(hst => hst.OtherColumn == 999),
foo => foo.Id,
hst => hst.Id,
(foo, hst) => foo.MapBar(hst.DefaultIfEmpty().First() != default
&& foo.OtherColumn == 1 ? 42 : null));
}
Код: Выделить всё
public static FooEntity MapBar(
this FooEntity foo,
int? bar)
{
foo.Bar = bar;
return foo;
}
Выражение LINQ... не может быть переведено
Другими словами, это работает:
Код: Выделить всё
... = await QueryFoosWithBar(... expression...).ToArrayAsync();
Код: Выделить всё
... = await QueryFoosWithBar(... expression...).OrderBy(f => f.Id).ToArrayAsync();
Код: Выделить всё
BarЭкземпляры Подробнее здесь: https://stackoverflow.com/questions/797 ... n-the-data
Мобильная версия