using System.Diagnostics;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace IssueConsoleTemplate
public int Id { get; set; }
public string Name { get; set; }
public BarVW Bar { get; set; }
public int FooId { get; set; }
public string FooName { get; set; }
public Foo Foo { get; set; }
public class Context : DbContext
public virtual DbSet<Foo> Foo { get; set; }
public virtual DbSet<BarVW> BarVW { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
FiddleHelper.GetConnectionStringSqlServer())
.UseLoggerFactory(LoggerFactory.Create(b => b
.AddFilter(level => level >= LogLevel.Information)))
.EnableSensitiveDataLogging()
protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Foo>()
new Foo {Id = 1, Name = "Fo"},
new Foo {Id = 2, Name = "Foo"},
new Foo {Id = 3, Name = "Fooo"});
modelBuilder.Entity<BarVW>(
.HasForeignKey<BarVW>(e => e.FooId);
public int Id { get; set; }
public string Name { get; set; }
public bool IsBar { get; set; }
internal static class Program
private static void Main()
using var context = new Context();
context.Database.EnsureCreated();
context.Database.ExecuteSqlRaw(
f.[Id] >= 1 and f.[Id] <= 2"
var config = new MapperConfiguration(
.CreateMap<Foo, FooDto>()
.ForMember(dto => dto.IsBar, opt => opt.MapFrom(src => src.Bar != null)));
.ProjectTo<FooDto>(config)
Debug.Assert(result.Count == 3);
Debug.Assert(result.Count(dto => dto.IsBar) == 2);