Closed
Description
openedon Oct 18, 2020
Hello all.
EF 5.0.0-rc.2.20475.6
using this semplificate :
public class Zoo
{
public Guid ID { get; set; }
public virtual ICollection<Animal> Animals { get; set; }
}
public class Nation
{
public Guid ID { get; set; }
public string Name { get; set; }
}
public class Animal
{
public Guid ID { get; set; }
public int Age { get; set; }
public virtual Nation BornNation { get; set; }
}
public class MyDBContext : DbContext
{
public MyDBContext()
{
this.Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlServer(@"Server=CRM3-NB01\SQLEXPRESS;Database=TestEF;Trusted_Connection=True;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Animal>().HasKey(itm => itm.ID);
modelBuilder.Entity<Animal>().HasOne(itm => itm.BornNation).WithMany().IsRequired(false);
modelBuilder.Entity<Zoo>().HasKey(itm => itm.ID);
modelBuilder.Entity<Zoo>().HasMany(itm => itm.Animals).WithOne().IsRequired(false);
modelBuilder.Entity<Nation>().HasKey(itm => itm.ID);
}
}
using this query :
using (var DB = new MyDBContext())
{
var q = (from itm in DB.Set<Zoo>().Include(itm => itm.Animals.Take(10)).ThenInclude(itm => itm.BornNation) select itm ).FirstOrDefault();
}
throw the exception :
Microsoft.Data.SqlClient.SqlException: 'Column name 'BornNationID' is not valid.
Column name 'Age' is not valid.
Column name 'BornNationID' is not valid.
Column name 'ZooID' is not valid'
No exception if I remove the Take(10) or if i use ToArray instead of FirstOrDefault
attached the project that reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment