Skip to content

Commit 342e6cb

Browse files
author
kostkams
committed
Generator generates: Class with normal properties, children and references
Transaction and Session can handle "create, get, update, delete" for generated classes
1 parent d2a3607 commit 342e6cb

36 files changed

+1047
-131
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using OrientDB.Net.Core.BusinessObjects;
2+
3+
namespace Proj1.Test
4+
{
5+
public class AddressBO : BusinessObject, IAddress
6+
{
7+
public AddressBO()
8+
{
9+
ClassName = "Address";
10+
}
11+
12+
[DocumentProperty("Name", true)]
13+
public string Name { get; set; }
14+
}
15+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Collections.Generic;
2+
using OrientDB.Net.Core.BusinessObjects;
3+
4+
namespace Proj1.Test
5+
{
6+
public class CompanyBO : BusinessObject, ICompany
7+
{
8+
public CompanyBO()
9+
{
10+
ClassName = "Company";
11+
Members = new ReferenceList<IMember>();
12+
}
13+
14+
[DocumentProperty("CompanyName", true)]
15+
public string Name { get; set; }
16+
[ReferenceList("hasMember")]
17+
public IList<IMember> Members { get; }
18+
}
19+
20+
public static class CompanyBOExtension
21+
{
22+
public static ICompany CreateCompany(this ITransaction transaction)
23+
{
24+
var company = new CompanyBO();
25+
transaction.Create(company);
26+
return company;
27+
}
28+
}
29+
}

Source/OrientDB.Net.Core.BusinessObjects.Console/CompanyBO.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using OrientDB.Net.Core.BusinessObjects;
2+
3+
namespace Proj1.Test
4+
{
5+
public interface IAddress : IBusinessObject
6+
{
7+
string Name { get; set; }
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
using OrientDB.Net.Core.BusinessObjects;
3+
4+
namespace Proj1.Test
5+
{
6+
public interface ICompany : IBusinessObject
7+
{
8+
string Name { get; set; }
9+
IList<IMember> Members { get; }
10+
}
11+
}

Source/OrientDB.Net.Core.BusinessObjects.Console/ICompanyBO.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using OrientDB.Net.Core.BusinessObjects;
2+
3+
namespace Proj1.Test
4+
{
5+
public interface IMember : IBusinessObject
6+
{
7+
string Name { get; set; }
8+
IAddress Address { get; }
9+
}
10+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using OrientDB.Net.Core.BusinessObjects;
3+
4+
namespace Proj1.Test
5+
{
6+
public class MemberBO : BusinessObject, IMember
7+
{
8+
public MemberBO()
9+
{
10+
ClassName = "Member";
11+
Address = new AddressBO();
12+
}
13+
14+
[DocumentProperty("Name", true)]
15+
public string Name { get; set; }
16+
[Child("memberAddress")]
17+
public IAddress Address { get; set; }
18+
}
19+
20+
public static class MemberBOExtension
21+
{
22+
public static IMember CreateMember(this ITransaction transaction)
23+
{
24+
var member = new MemberBO();
25+
transaction.Create(member);
26+
return member;
27+
}
28+
}
29+
}

Source/OrientDB.Net.Core.BusinessObjects.Console/OrientDB.Net.Core.BusinessObjects.Console.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\OrientDB.Net.Core.BusinessObjects.Generator\OrientDB.Net.Core.BusinessObjects.Generator.csproj" />
914
<ProjectReference Include="..\OrientDB.Net.Core.BusinessObjects\OrientDB.Net.Core.BusinessObjects.csproj" />
1015
</ItemGroup>
1116

Source/OrientDB.Net.Core.BusinessObjects.Console/Program.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Linq;
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Newtonsoft.Json;
4+
using OrientDB.Net.Core.BusinessObjects.Generator;
5+
using Proj1.Test;
26

37
namespace OrientDB.Net.Core.BusinessObjects.Console
48
{
@@ -15,21 +19,28 @@ private static void Main(string[] args)
1519

1620
using (var session = businessDocument.OpenSession())
1721
{
18-
var company = session.Get<ICompanyBO>(e => "Test" == e.Name && (e.Name != "tu" || e.Name != "tsssu") /**/);
1922
var transaction = session.BeginTransaction();
2023
var comp = transaction.CreateCompany();
2124
comp.Name = "Neu";
25+
var member = transaction.CreateMember();
26+
member.Name = "Member";
27+
member.Address.Name = "Haus";
28+
comp.Members.Add(member);
2229
transaction.Commit();
23-
var company1 = session.Get<ICompanyBO>();
30+
2431

2532
transaction = session.BeginTransaction();
2633
comp.Name = "Neu 1";
34+
member = comp.Members.First();
35+
member.Name = "Member 1";
36+
member.Address.Name = "Haus 1";
2737
transaction.Update(comp);
2838
transaction.Commit();
2939

3040

3141
transaction = session.BeginTransaction();
32-
transaction.Delete(session.Get<ICompanyBO>(c => c.Name == "Neu 1").First());
42+
var companyFromDB = session.Get<ICompany>(c => c.Name == "Neu 1").First();
43+
transaction.Delete(companyFromDB);
3344
transaction.Commit();
3445
}
3546
}

0 commit comments

Comments
 (0)