Last active
December 25, 2015 03:29
-
-
Save kijanawoodard/6909759 to your computer and use it in GitHub Desktop.
Load and Include shared Guid Id using 2700
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//duplicate guid id | |
//you get three documents created under the proper collections, but you can't include by just the Guid, even with the generic type specified | |
public class MailingListIncludeTest : RavenTestBase | |
{ | |
[Test] | |
public void Test() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
EntityA a = new EntityA { Id = Guid.NewGuid() }; | |
EntityB b = new EntityB { Id = a.Id }; | |
EntityC c = new EntityC { Id = Guid.NewGuid(), EntityAId = a.Id, EntityBId = b.Id }; | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(a); | |
session.Store(b); | |
session.Store(c); | |
session.SaveChanges(); | |
Assert.AreEqual(store.DatabaseCommands.GetStatistics().CountOfDocuments, 3); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var resultC = | |
session | |
.Include<EntityC, EntityA>(x => x.EntityAId) | |
.Include<EntityB>(x => x.EntityBId) | |
.Load<EntityC>(c.Id); | |
var resultA = session.Load<EntityA>(a.Id); | |
var resultB = session.Load<EntityB>(b.Id); | |
Assert.AreEqual(1, session.Advanced.NumberOfRequests); | |
Assert.NotNull(resultC, "resultC"); | |
Assert.NotNull(resultA, "resultA"); | |
Assert.NotNull(resultB, "resultB - Include"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using string ids works fine | |
public class MailingListIncludeTest2 : RavenTestBase | |
{ | |
[Test] | |
public void Test() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
EntityA a = new EntityA { External = Guid.NewGuid() }; | |
EntityB b = new EntityB { External = a.External }; | |
EntityC c = new EntityC { External = Guid.NewGuid(), EntityAId = a.Id, EntityBId = b.Id }; | |
using (var session = store.OpenSession()) | |
{ | |
session.Store(a); | |
session.Store(b); | |
session.Store(c); | |
session.SaveChanges(); | |
//Assert.AreEqual(store.DatabaseCommands.GetStatistics().CountOfDocuments, 3); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var resultA = session.Load<EntityA>(c.EntityAId); | |
var resultB = session.Load<EntityB>(c.EntityBId); | |
var resultC = session.Load<EntityC>(c.Id); | |
Assert.NotNull(resultA, "resultA"); | |
Assert.NotNull(resultB, "resultB"); | |
Assert.NotNull(resultC, "resultC"); | |
Assert.AreEqual(session.Advanced.NumberOfRequests, 3); | |
} | |
using (var session = store.OpenSession()) | |
{ | |
var resultC = | |
session | |
.Include<EntityC, EntityA>(x => x.EntityAId) | |
.Include<EntityB>(x => x.EntityBId) | |
.Load<EntityC>(c.Id); | |
var resultA = session.Load<EntityA>(a.Id); | |
var resultB = session.Load<EntityB>(b.Id); | |
Assert.AreEqual(1, session.Advanced.NumberOfRequests); | |
Assert.NotNull(resultC, "resultC"); | |
Assert.NotNull(resultA, "resultA"); | |
Assert.NotNull(resultB, "resultB"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment