-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Did a test with a many to many mapping between roles and privledges
- Loading branch information
Showing
9 changed files
with
106 additions
and
88 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Domain; | ||
using FluentNHibernate.Mapping; | ||
|
||
namespace Console | ||
{ | ||
public class RoleMap : ClassMap<Role> | ||
{ | ||
public RoleMap() | ||
{ | ||
Id(x => x.Id); | ||
Map(x => x.Name).Not.Nullable(); | ||
Map(x => x.TypeOfContent) | ||
.Access.CamelCaseField(Prefix.Underscore) | ||
.CustomType<string>(); | ||
HasManyToMany(x => x.Privileges) | ||
.Cascade.All() | ||
.Table("RolePrivilege"); | ||
Table("roles"); | ||
} | ||
} | ||
|
||
public class PrivilegeMap : ClassMap<Privilege> | ||
{ | ||
public PrivilegeMap() | ||
{ | ||
Id(x => x.Id); | ||
Map(x => x.Path).Not.Nullable(); | ||
HasManyToMany(x => x.RolesWithThisPrivilege) | ||
.Cascade.All() | ||
.Inverse() | ||
.Table("RolePrivilege"); | ||
Table("privileges"); | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Domain | ||
{ | ||
public class EntityBase<T> : PersistentBase | ||
|
||
public interface IAggregateRoot | ||
{ | ||
private T _id = default(T); | ||
|
||
public virtual T Id | ||
{ | ||
get | ||
{ | ||
return _id; | ||
} | ||
private set | ||
{ | ||
_id = value; | ||
} | ||
} | ||
} | ||
|
||
public abstract class PersistentBase | ||
{} | ||
public enum DefaultRoleNames | ||
{ | ||
Role1, | ||
Role2, | ||
Role3 | ||
} | ||
|
||
public class TestEntityA : EntityBase<int> | ||
public class Role : IAggregateRoot | ||
{ | ||
private string _name; | ||
public virtual int Id { get; private set; } | ||
public virtual DefaultRoleNames Name { get; set; } | ||
public virtual IList<Privilege> Privileges { get; set; } | ||
|
||
public virtual string Name | ||
private string _typeOfContent; | ||
|
||
public virtual Type TypeOfContent | ||
{ | ||
get { return _name; } | ||
set { _name = value; } | ||
get { return Type.GetType(_typeOfContent); } | ||
set { _typeOfContent = value.FullName; } | ||
} | ||
|
||
private IList<TestEntityB> _children = new List<TestEntityB>(); | ||
|
||
public virtual IEnumerable<TestEntityB> Children | ||
public Role() | ||
{ | ||
get { return _children; } | ||
//protected set { _children = value.ToList(); } | ||
Privileges = new List<Privilege>(); | ||
} | ||
|
||
public virtual void AddChild(TestEntityB b) | ||
public virtual void AddPrivilege(Privilege privilege) | ||
{ | ||
_children.Add(b); | ||
b.TestEntityA = this; | ||
privilege.RolesWithThisPrivilege.Add(this); | ||
Privileges.Add(privilege); | ||
} | ||
} | ||
|
||
public class TestEntityB : EntityBase<int> | ||
public class Privilege : IAggregateRoot | ||
{ | ||
private string _comment; | ||
|
||
public virtual string Comment | ||
public virtual int Id { get; private set; } | ||
public virtual string Path { get; set; } | ||
public virtual IList<Role> RolesWithThisPrivilege | ||
{ | ||
get { return _comment; } | ||
set { _comment = value; } | ||
get; | ||
private set; | ||
} | ||
|
||
private TestEntityA _testEntityA = null; | ||
|
||
public virtual TestEntityA TestEntityA | ||
public Privilege() | ||
{ | ||
get { return _testEntityA; } | ||
set { _testEntityA = value; } | ||
RolesWithThisPrivilege = new List<Role>(); | ||
} | ||
} | ||
} |
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