-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Description
Bug description
If there are two List Creations in a projection and in one of them there are only static values. The results share the same List.
But each Result should have its own list.
Your code
[TestMethod]
public async Task NoStaticListTest()
{
var ctx = new NoStaticListDbContext();
ctx.Database.EnsureCreated();
ctx.Es.Add(new E() { Id = "1", City = "A" });
ctx.Es.Add(new E() { Id = "2", City = "B" });
await ctx.SaveChangesAsync();
ctx.ChangeTracker.Clear();
var result = await ctx.Es.Select(_ => new EDto { Id = _.Id, Sources = new List<string> { "NoStaticListDbContext" }, Addresses = new List<Address> { new Address { City = _.City } } }).ToListAsync();
result[0].Sources.Add("b");
result[1].Sources.Should().HaveCount(1);
}
public class NoStaticListDbContext : DbContext
{
public DbSet<E> Es { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost;Database=One;Integrated Security=True;Trust Server Certificate=True");
}
}
public class E
{
public string Id { get; set; }
//public string Zip { get; set; }
public string City { get; set; }
//public string Street { get; set; }
//public string Number { get; set; }
}
public class EDto
{
public string Id { get; set; }
public List<string> Sources { get; set; }
public List<Address> Addresses { get; set; }
}
public class Address
{
public string City { get; set; }
}
Stack traces
Verbose output
EF Core version
9.0.9
Database provider
No response
Target framework
.NET 8.0
Operating system
No response
IDE
No response