Created
May 12, 2014 10:40
-
-
Save pil0t/212cd5bc62d67ceb44fb to your computer and use it in GitHub Desktop.
TestDOEntitySet
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TestDOEntitySet | |
{ | |
using Xtensive.Orm; | |
using Xtensive.Orm.Building; | |
using Xtensive.Orm.Building.Definitions; | |
using Xtensive.Orm.Configuration; | |
[HierarchyRoot] | |
public class MyTestEntity : Entity | |
{ | |
[Key] | |
[Field] | |
public Guid Id { get; private set; } | |
[Field] | |
public string Name { get; set; } | |
[Field] | |
public EntitySet<Entity2> ES { get; set; } | |
} | |
[HierarchyRoot] | |
public class Entity2 : Entity | |
{ | |
[Key] | |
[Field] | |
public Guid Id { get; private set; } | |
[Field] | |
public string Name { get; set; } | |
} | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
var domainConfiguration = new DomainConfiguration("sqlserver://localhost/DO40-Tests"); | |
domainConfiguration.Types.Register(typeof(MyTestEntity).Assembly); | |
domainConfiguration.UpgradeMode = DomainUpgradeMode.Recreate; | |
using (var domain = Domain.Build(domainConfiguration)) | |
{ | |
using (var s = domain.OpenSession()) | |
using (s.Activate()) | |
using (var t = Session.Current.OpenTransaction()) | |
{ | |
var n = 10; | |
var e1 = new MyTestEntity() { Name = "Test" }; | |
var e2 = new Entity2() { Name = "1" }; | |
e1.ES.Add(e2); | |
var e3 = new Entity2() { Name = "2" }; | |
t.Complete(); | |
} | |
var ds = new DisconnectedState(); | |
using (var s = domain.OpenSession()) | |
using (s.Activate()) | |
using (ds.Attach(s)) | |
using (ds.Connect()) | |
using (var t = Session.Current.OpenTransaction()) | |
{ | |
var e1 = Query.All<MyTestEntity>().Single(); | |
var e2 = Query.All<Entity2>().Where(a => a.Name.Contains("2")).ToArray(); | |
e1.Name = "Test2"; // whithout this OK | |
e1.ES.UnionWith(e2); | |
var array = e1.ES.ToArray(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment