我的数据库中有现有的表,需要创建一个域来处理现有数据。
我有下一个表结构:
Application
'ORDERSCANNER'
ApplicationFunction
'ORDERSCANNER','SCAN'
'ORDERSCANNER','READ'
'ORDERSCANNER','PRINT'
FunctionalGroup
'ADMIN','RUS','ORDERSCANNER','SCAN'
'ADMIN','RUS','ORDERSCANNER','PRINT'
'ADMIN','JAP','ORDERSCANNER','SCAN'
'ADMIN','JAP','ORDERSCANNER','PRINT'
'OPERATOR','RUS','ORDERSCANNER','SCAN'
'OPERATOR','JAP','ORDERSCANNER','SCAN'
User
'IVANOV','RUS','OPERATOR'
'PETROV','RUS','OPERATOR'
'PETROV','JAP','OPERATOR'
'SIDOROV','RUS','ADMIN - he is an ADMIN group but only for RUS. He is not able to scan for JAP
这是我如何看待我的域
public class Application // root
{
private readonly List<ApplicationFunction> _functions;
public string ApplicationId { get; set; }
public Application()
{
_functions = new List<ApplicationFunction>();
}
public void AddFunction(string newFunction)
{
var function = new ApplicationFunction(this, newFunction);
_functions.Add(function);
}
}
public class ApplicationFunction // value object
{
public Application Application { get; private set; }
public string FunctionId { get; private set; }
public ApplicationFunction(Application application, string functionId)
{
if (application == null) throw new ArgumentNullException("application");
if (functionId == null) throw new ArgumentNullException("functionId");
Application = application;
FunctionId = functionId;
}
}
public class FunctionalGroup // root
{
private readonly List<ApplicationFunction> _functions;
public string GroupId { get; set; }
public string MarketingPlanCode { get; set; }
public IEnumerable<ApplicationFunction> Functions { get { return _functions; } }
public FunctionalGroup()
{
_functions = new List<ApplicationFunction>();
}
public void AddFunction(ApplicationFunction applicationFunction)
{
_functions.Add(applicationFunction);
}
}
public class User // root
{
private readonly List<FunctionalGroup> _groups;
public string UserId { get; set; }
public IEnumerable<FunctionalGroup> Groups { get { return _groups; } }
public User()
{
_groups = new List<FunctionalGroup>();
}
public void AddToGroup(FunctionalGroup functionalGroup)
{
_groups.Add(functionalGroup);
}
}
让我们看看用户。
public class UserMap : ClassMap<User>
{
public UserMap()
{
Id(x => x.UserId).Column("USER_ID");
HasMany(x => x.Groups).Cascade.All();
}
}
看起来我需要额外的数据来映射我的 FunctionalGroup 集合 - 它是 MarketingPlanCode。如果我将 MarketingPlanCode 属性添加到我的 User 类中,每个集合将只获得一个属性。但是我需要该集合中的每个项目的 I 属性。
好吧,如果我无法解释我需要什么,请查看我表中的示例数据。有没有办法映射它?