1

Closed

Single db record not mapped to same object in one query

description

if (!db.TestAs.Any())
        {
            db.TestAs.Insert(new TestA
                                 {
                                         Id = Guid.NewGuid(),
                                         Name = "xx",
                                 });
            db.TestAs.Insert(new TestA
                                 {
                                         Id = Guid.NewGuid(),
                                         Name = "yy",
                                 });
            db.TestBs.Insert(new TestB
                                 {
                                         Id = Guid.NewGuid(),
                                         Name = "xx",
                                 });
            db.TestBs.Insert(new TestB
                                 {
                                         Id = Guid.NewGuid(),
                                         Name = "xx",
                                 });
        }
        var v =
                (from a in db.TestAs
                 join b in db.TestBs on a.Name equals b.Name
 
                 select new { a, b }).ToList();
 
        Debug.Assert(v.Count == 2); // ok
        Debug.Assert(ReferenceEquals(v[0].a, v[1].a)); //failed
 
 
 
public class TestA
{
    public Guid Id { get; set; }
 
    public string Name { get; set; }
}
 
public class TestB
{
    public Guid Id { get; set; }
 
    public string Name { get; set; }
}
Closed Apr 20, 2012 at 6:32 PM by mattwar
This is not an intended behavior of the EntityProvider class. You can get this behavior by using the EntitySession class.

comments

mattwar wrote Apr 20, 2012 at 6:32 PM

You can get this behavior by using an EntitySession object. See the NorthwindSession class used in the tests.

wrote Apr 20, 2012 at 6:32 PM

wrote Feb 14, 2013 at 7:44 PM

wrote May 16, 2013 at 9:59 AM