diff --git a/UserService.DatabaseLayer/DataModels/UserDatabase.generated.cs b/UserService.DatabaseLayer/DataModels/UserDatabase.generated.cs
new file mode 100644
index 0000000..0f251f6
--- /dev/null
+++ b/UserService.DatabaseLayer/DataModels/UserDatabase.generated.cs
@@ -0,0 +1,205 @@
+//---------------------------------------------------------------------------------------------------
+//
+// This code was generated by T4Model template for T4 (https://github.com/linq2db/linq2db).
+// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
+//
+//---------------------------------------------------------------------------------------------------
+
+#pragma warning disable 1591
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using LinqToDB;
+using LinqToDB.Mapping;
+
+namespace DataModels
+{
+ ///
+ /// Database : UserDatabase
+ /// Data Source : srvbo
+ /// Server Version : 5.5.5-10.3.22-MariaDB-1ubuntu1
+ ///
+ public partial class UserDatabaseDB : LinqToDB.Data.DataConnection
+ {
+ public ITable Members { get { return this.GetTable(); } }
+ public ITable MembersMembers { get { return this.GetTable(); } }
+ public ITable Nodes { get { return this.GetTable(); } }
+ public ITable OrganizationUnits { get { return this.GetTable(); } }
+ public ITable SecurityGroups { get { return this.GetTable(); } }
+ public ITable Users { get { return this.GetTable(); } }
+
+ public UserDatabaseDB()
+ {
+ InitDataContext();
+ InitMappingSchema();
+ }
+
+ public UserDatabaseDB(string configuration)
+ : base(configuration)
+ {
+ InitDataContext();
+ InitMappingSchema();
+ }
+
+ partial void InitDataContext ();
+ partial void InitMappingSchema();
+ }
+
+ [Table("Members")]
+ public partial class Member
+ {
+ [Column, NotNull] public int Id { get; set; } // int(11)
+
+ #region Associations
+
+ ///
+ /// MembersMember_ibfk_2_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="AttachedMemberId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable MembersMemberIbfk2BackReferences { get; set; }
+
+ ///
+ /// MembersMember_ibfk_1_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="MemberId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable MembersMemberibfks { get; set; }
+
+ ///
+ /// Members_ibfk_1
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="Members_ibfk_1", BackReferenceName="Membersibfks")]
+ public Node Node { get; set; }
+
+ ///
+ /// SecurityGroups_ibfk_1_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable SecurityGroupsibfks { get; set; }
+
+ ///
+ /// Users_ibfk_1_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable Usersibfks { get; set; }
+
+ #endregion
+ }
+
+ [Table("MembersMember")]
+ public partial class MembersMember
+ {
+ [PrimaryKey(1), NotNull] public int MemberId { get; set; } // int(11)
+ [PrimaryKey(2), NotNull] public int AttachedMemberId { get; set; } // int(11)
+
+ #region Associations
+
+ ///
+ /// MembersMember_ibfk_2
+ ///
+ [Association(ThisKey="AttachedMemberId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="MembersMember_ibfk_2", BackReferenceName="MembersMemberIbfk2BackReferences")]
+ public Member AttachedMember { get; set; }
+
+ ///
+ /// MembersMember_ibfk_1
+ ///
+ [Association(ThisKey="MemberId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="MembersMember_ibfk_1", BackReferenceName="MembersMemberibfks")]
+ public Member Member { get; set; }
+
+ #endregion
+ }
+
+ [Table("Nodes")]
+ public partial class Node
+ {
+ [PrimaryKey, Identity] public int Id { get; set; } // int(11)
+
+ #region Associations
+
+ ///
+ /// Members_ibfk_1_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable Membersibfks { get; set; }
+
+ ///
+ /// OrganizationUnits_ibfk_1_BackReference
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
+ public IEnumerable OrganizationUnitsibfks { get; set; }
+
+ #endregion
+ }
+
+ [Table("OrganizationUnits")]
+ public partial class OrganizationUnit
+ {
+ [Column, NotNull ] public int Id { get; set; } // int(11)
+ [Column, Nullable] public int? ManagerId { get; set; } // int(11)
+ [Column, Nullable] public int? ParentId { get; set; } // int(11)
+
+ #region Associations
+
+ ///
+ /// OrganizationUnits_ibfk_1
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="OrganizationUnits_ibfk_1", BackReferenceName="OrganizationUnitsibfks")]
+ public Node Node { get; set; }
+
+ #endregion
+ }
+
+ [Table("SecurityGroups")]
+ public partial class SecurityGroup
+ {
+ [Column, NotNull] public int Id { get; set; } // int(11)
+
+ #region Associations
+
+ ///
+ /// SecurityGroups_ibfk_1
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="SecurityGroups_ibfk_1", BackReferenceName="SecurityGroupsibfks")]
+ public Member Member { get; set; }
+
+ #endregion
+ }
+
+ [Table("Users")]
+ public partial class User
+ {
+ [Column, NotNull ] public int Id { get; set; } // int(11)
+ [Column, Nullable] public string FirstName { get; set; } // text
+ [Column, Nullable] public string LastName { get; set; } // text
+ [Column, NotNull ] public bool IsActive { get; set; } // bit(1)
+
+ #region Associations
+
+ ///
+ /// Users_ibfk_1
+ ///
+ [Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="Users_ibfk_1", BackReferenceName="Usersibfks")]
+ public Member Member { get; set; }
+
+ #endregion
+ }
+
+ public static partial class TableExtensions
+ {
+ public static MembersMember Find(this ITable table, int MemberId, int AttachedMemberId)
+ {
+ return table.FirstOrDefault(t =>
+ t.MemberId == MemberId &&
+ t.AttachedMemberId == AttachedMemberId);
+ }
+
+ public static Node Find(this ITable table, int Id)
+ {
+ return table.FirstOrDefault(t =>
+ t.Id == Id);
+ }
+ }
+}
+
+#pragma warning restore 1591
diff --git a/UserService.DatabaseLayer/DataModels/UserDatabase.tt b/UserService.DatabaseLayer/DataModels/UserDatabase.tt
new file mode 100644
index 0000000..e36269d
--- /dev/null
+++ b/UserService.DatabaseLayer/DataModels/UserDatabase.tt
@@ -0,0 +1,54 @@
+<#@ template language="C#" debug="True" hostSpecific="True" #>
+<#@ output extension=".generated.cs" #>
+<#@ include file="$(LinqToDBT4MySqlTemplatesDirectory)LinqToDB.MySql.Tools.ttinclude" #>
+<#@ include file="$(LinqToDBT4MySqlTemplatesDirectory)PluralizationService.ttinclude" #>
+<# //@ include file="$(ProjectDir)LinqToDB.Templates\LinqToDB.MySql.Tools.ttinclude" #>
+<# //@ include file="$(ProjectDir)LinqToDB.Templates\PluralizationService.ttinclude" #>
+<#
+ /*
+ 1. Create new *.tt file (e.g. MyDatabase.tt) in a folder where you would like to generate your data model
+ and copy content from this file to it. For example:
+
+ MyProject
+ DataModels
+ MyDatabase.tt
+
+ 2. Modify the connection settings below to connect to your database.
+
+ 3. Add connection string to the web/app.config file:
+
+
+
+
+
+ 4. To access your database use the following code:
+
+ using (var db = new MyDatabaseDB())
+ {
+ var q =
+ from c in db.Customers
+ select c;
+
+ foreach (var c in q)
+ Console.WriteLine(c.ContactName);
+ }
+
+ 5. See more at https://linq2db.github.io/articles/T4.html
+
+ IMPORTANT: if running .tt file gives you error like this:
+ "error : Failed to resolve include text for file: C:\...\$(LinqToDBT4TemplatesDirectory)LinqToDB..Tools.ttinclude"
+ check tt file properties.
+ Custom tool must be set to TextTemplatingFileGenerator, not TextTemplatingFilePreprocessor or any other value.
+ */
+
+ NamespaceName = "DataModels";
+
+ // to configure GetSchemaOptions properties, add them here, before load metadata call
+
+ LoadMySqlMetadata("srvbo", "UserDatabase", "UserDbAdmin", "12345678");
+// LoadMySqlMetadata(string connectionString);
+
+ // to adjust loaded database model before generation, add your code here, after load metadata, but before GenerateModel() call
+
+ GenerateModel();
+#>
diff --git a/UserService.DatabaseLayer/UserService.DatabaseLayer.csproj b/UserService.DatabaseLayer/UserService.DatabaseLayer.csproj
index 517c6c0..9e90ae7 100644
--- a/UserService.DatabaseLayer/UserService.DatabaseLayer.csproj
+++ b/UserService.DatabaseLayer/UserService.DatabaseLayer.csproj
@@ -1,4 +1,4 @@
-
+
netcoreapp3.1
@@ -7,19 +7,42 @@
+
+ True
+ True
+ UserDatabase.tt
+
+
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
+
+
+
+
+ True
+ True
+ UserDatabase.tt
+
+
+
+
+
+ TextTemplatingFileGenerator
+ UserDatabase.generated.cs
+
+
+
diff --git a/UserService.Infrastructure/DataModels/Node.cs b/UserService.Infrastructure/DataModels/Node.cs
index 440fd9a..5d7dfd5 100644
--- a/UserService.Infrastructure/DataModels/Node.cs
+++ b/UserService.Infrastructure/DataModels/Node.cs
@@ -24,7 +24,7 @@ namespace UserService.Infrastructure.DataModels
public int CompareTo(Node? other)
{
if (ReferenceEquals(this, other)) return 0;
- if (ReferenceEquals(null, other)) return 1;
+ if (other is null) return 1;
var commonNameComparison = string.Compare(CommonName, other.CommonName, StringComparison.Ordinal);
if (commonNameComparison != 0) return commonNameComparison;
return Id.CompareTo(other.Id);