try another way to implement the data stucture
This commit is contained in:
@ -15,29 +15,25 @@ using System.Linq;
|
||||
using LinqToDB;
|
||||
using LinqToDB.Mapping;
|
||||
|
||||
namespace DataModels
|
||||
namespace UserService.DatabaseLayer.DataModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Database : UserService
|
||||
/// Database : UserService2
|
||||
/// Data Source : srvbo
|
||||
/// Server Version : 5.5.5-10.3.22-MariaDB-1ubuntu1
|
||||
/// </summary>
|
||||
public partial class UserServiceDB : LinqToDB.Data.DataConnection
|
||||
public partial class UserService2DB : LinqToDB.Data.DataConnection
|
||||
{
|
||||
public ITable<Member> Members { get { return this.GetTable<Member>(); } }
|
||||
public ITable<MembersMember> MembersMembers { get { return this.GetTable<MembersMember>(); } }
|
||||
public ITable<Node> Nodes { get { return this.GetTable<Node>(); } }
|
||||
public ITable<OrganizationUnit> OrganizationUnits { get { return this.GetTable<OrganizationUnit>(); } }
|
||||
public ITable<SecurityGroup> SecurityGroups { get { return this.GetTable<SecurityGroup>(); } }
|
||||
public ITable<User> Users { get { return this.GetTable<User>(); } }
|
||||
public ITable<IsMemberOf> IsMemberOfs { get { return this.GetTable<IsMemberOf>(); } }
|
||||
public ITable<NodeModel> NodeModels { get { return this.GetTable<NodeModel>(); } }
|
||||
|
||||
public UserServiceDB()
|
||||
public UserService2DB()
|
||||
{
|
||||
InitDataContext();
|
||||
InitMappingSchema();
|
||||
}
|
||||
|
||||
public UserServiceDB(string configuration)
|
||||
public UserService2DB(string configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
InitDataContext();
|
||||
@ -48,167 +44,94 @@ namespace DataModels
|
||||
partial void InitMappingSchema();
|
||||
}
|
||||
|
||||
[Table("Members")]
|
||||
public partial class Member
|
||||
[Table("IsMemberOf")]
|
||||
public partial class IsMemberOf
|
||||
{
|
||||
[Column, NotNull] public int Id { get; set; } // int(11)
|
||||
[PrimaryKey(1), NotNull] public int NodeId { get; set; } // int(11)
|
||||
[PrimaryKey(2), NotNull] public int NodeMemberId { get; set; } // int(11)
|
||||
|
||||
#region Associations
|
||||
|
||||
/// <summary>
|
||||
/// MembersMember_ibfk_2_BackReference
|
||||
/// IsMemberOf_ibfk_1
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="AttachedMemberId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<MembersMember> MembersMemberibfks { get; set; } = null!;
|
||||
[Association(ThisKey="NodeId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="IsMemberOf_ibfk_1", BackReferenceName="IsMemberOfibfks")]
|
||||
public NodeModel Node { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Members_ibfk_2
|
||||
/// IsMemberOf_ibfk_2
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="Members_ibfk_2", BackReferenceName="Membersibfks")]
|
||||
public Node Node { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// SecurityGroups_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<SecurityGroup> SecurityGroupsibfks { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Users_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<User> Usersibfks { get; set; } = null!;
|
||||
[Association(ThisKey="NodeMemberId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="IsMemberOf_ibfk_2", BackReferenceName="IsMemberOfIbfk2BackReferences")]
|
||||
public NodeModel NodeMember { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Table("MembersMember")]
|
||||
public partial class MembersMember
|
||||
[Table("NodeModels")]
|
||||
public partial class NodeModel
|
||||
{
|
||||
[PrimaryKey(1), NotNull] public int MemberId { get; set; } // int(11)
|
||||
[PrimaryKey(2), NotNull] public int AttachedMemberId { get; set; } // int(11)
|
||||
[PrimaryKey, Identity ] public int Id { get; set; } // int(11)
|
||||
[Column, NotNull ] public string CommonName { get; set; } = null!; // varchar(64)
|
||||
[Column, Nullable] public string? FirstName { get; set; } // text
|
||||
[Column, Nullable] public string? LastName { get; set; } // text
|
||||
[Column, Nullable] public string? Description { get; set; } // text
|
||||
[Column, Nullable] public int? ParentId { get; set; } // int(11)
|
||||
[Column, Nullable] public int? ManagerId { get; set; } // int(11)
|
||||
[Column, Nullable] public string? EMail { get; set; } // text
|
||||
[Column, NotNull ] public bool IsActive { get; set; } // bit(1)
|
||||
[Column, NotNull ] public string Discriminator { get; set; } = null!; // text
|
||||
|
||||
#region Associations
|
||||
|
||||
/// <summary>
|
||||
/// MembersMember_ibfk_2
|
||||
/// NodeModels_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="AttachedMemberId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="MembersMember_ibfk_2", BackReferenceName="MembersMemberibfks")]
|
||||
public Member AttachedMember { get; set; } = null!;
|
||||
[Association(ThisKey="Id", OtherKey="ManagerId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<NodeModel> Ibfks { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// MembersMember_ibfk_3
|
||||
/// IsMemberOf_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="MemberId", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="MembersMember_ibfk_3", BackReferenceName="MembersMemberibfks")]
|
||||
public SecurityGroup Member { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Table("Nodes")]
|
||||
public partial class Node
|
||||
{
|
||||
[PrimaryKey, Identity] public int Id { get; set; } // int(11)
|
||||
[Column, NotNull ] public string CommonName { get; set; } = null!; // text
|
||||
|
||||
#region Associations
|
||||
[Association(ThisKey="Id", OtherKey="NodeMemberId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<IsMemberOf> IsMemberOfIbfk2BackReferences { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Members_ibfk_2_BackReference
|
||||
/// IsMemberOf_ibfk_1_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<Member> Membersibfks { get; set; } = null!;
|
||||
[Association(ThisKey="Id", OtherKey="NodeId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<IsMemberOf> IsMemberOfibfks { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// OrganizationUnits_ibfk_2_BackReference
|
||||
/// NodeModels_ibfk_2
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<OrganizationUnit> OrganizationUnitsibfks { get; set; } = null!;
|
||||
|
||||
#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
|
||||
[Association(ThisKey="ManagerId", OtherKey="Id", CanBeNull=true, Relationship=Relationship.ManyToOne, KeyName="NodeModels_ibfk_2", BackReferenceName="Ibfks")]
|
||||
public NodeModel? Manager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OrganizationUnits_ibfk_3_BackReference
|
||||
/// NodeModels_ibfk_3_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="ParentId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<OrganizationUnit> Ibfks { get; set; } = null!;
|
||||
public IEnumerable<NodeModel> NodeModelsIbfk3BackReferences { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// OrganizationUnits_ibfk_2
|
||||
/// NodeModels_ibfk_3
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="OrganizationUnits_ibfk_2", BackReferenceName="OrganizationUnitsibfks")]
|
||||
public Node Node { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// OrganizationUnits_ibfk_3
|
||||
/// </summary>
|
||||
[Association(ThisKey="ParentId", OtherKey="Id", CanBeNull=true, Relationship=Relationship.ManyToOne, KeyName="OrganizationUnits_ibfk_3", BackReferenceName="Ibfks")]
|
||||
public OrganizationUnit? Parent { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Table("SecurityGroups")]
|
||||
public partial class SecurityGroup
|
||||
{
|
||||
[Column, NotNull] public int Id { get; set; } // int(11)
|
||||
|
||||
#region Associations
|
||||
|
||||
/// <summary>
|
||||
/// SecurityGroups_ibfk_2
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="SecurityGroups_ibfk_2", BackReferenceName="SecurityGroupsibfks")]
|
||||
public Member Member { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// MembersMember_ibfk_3_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="MemberId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<MembersMember> MembersMemberibfks { get; set; } = null!;
|
||||
|
||||
#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
|
||||
|
||||
/// <summary>
|
||||
/// Users_ibfk_2
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="Id", CanBeNull=false, Relationship=Relationship.ManyToOne, KeyName="Users_ibfk_2", BackReferenceName="Usersibfks")]
|
||||
public Member Member { get; set; } = null!;
|
||||
[Association(ThisKey="ParentId", OtherKey="Id", CanBeNull=true, Relationship=Relationship.ManyToOne, KeyName="NodeModels_ibfk_3", BackReferenceName="NodeModelsIbfk3BackReferences")]
|
||||
public NodeModel? Parent { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static partial class TableExtensions
|
||||
{
|
||||
public static MembersMember Find(this ITable<MembersMember> table, int MemberId, int AttachedMemberId)
|
||||
public static IsMemberOf Find(this ITable<IsMemberOf> table, int NodeId, int NodeMemberId)
|
||||
{
|
||||
return table.FirstOrDefault(t =>
|
||||
t.MemberId == MemberId &&
|
||||
t.AttachedMemberId == AttachedMemberId);
|
||||
t.NodeId == NodeId &&
|
||||
t.NodeMemberId == NodeMemberId);
|
||||
}
|
||||
|
||||
public static Node Find(this ITable<Node> table, int Id)
|
||||
public static NodeModel Find(this ITable<NodeModel> table, int Id)
|
||||
{
|
||||
return table.FirstOrDefault(t =>
|
||||
t.Id == Id);
|
||||
|
Reference in New Issue
Block a user