这个问题的重点主要是在给定对象模型的情况下开发一个关系数据库方案。
系统的这一部分涉及资源(不同类型的员工和承包商)对活动(项目或帐户)进行的基于时间的分配。数据输入是每周一次,域模型必须验证每周输入(每个资源大约 5 个,有 200 个资源),然后才能持久化它们。来自数据库的查询必须支持按活动和资源对分配的批准/分析。
我已经在系统的简单部分中使用了 NHib (& FNH),因此我的主要关注点是充实领域模型必须做出的其他让步,以便持久使用这些工具。例如:
1) 本来不是虚拟的属性是虚拟的
2) id 生成(作为基类的实体被自动映射以生成 ID (int)
以下是感兴趣的领域类,为了演示目的进行了测试:
public class Allocation : Entity {
public virtual ResourceBase Resource { get; private set; }
public virtual ActivityBase Activity { get; private set; }
public virtual TimeQuantity TimeSpent { get private set; }
}
public abstract class AllocatableBase : Entity {
protected readonly IDictionary<DateTime, Allocation> _allocations = new SortedList<DateTime, Allocation>();
public virtual IEnumerable<Allocation> Allocations { get { return _allocations.Values; } }
}
public abstract class ResourceBase : AllocatableBase {
public virtual string Name { get; protected set; }
public virtual string BusinessId { get; protected set; }
public virtual string OrganizationName { get; protected set; }
}
// example of a concrete ResourceBase
public sealed class StaffMemberResource : ResourceBase {
public StaffMember StaffMember { get; private set; }
public StaffMemberResource(StaffMember staffMember)
{
Check.RequireNotNull<StaffMember>(staffMember);
UniqueId = GetType().Name + " " + staffMember.Number; // bad smell here
Name = staffMember.Name.ToString();
BusinessId = staffMember.Number;
OrganizationName = staffMember.Department.Name;
StaffMember = staffMember;
}
}
public abstract class ActivityBase : AllocatableBase {
public virtual void ClockIn(DateTime eventDate, ResourceBase resource, TimeQuantity timeSpent) {
... add to the set of allocations if valid
}
public virtual string Description { get; protected set; }
public virtual string BusinessId { get; protected set; }
}
// example of a concrete ActivityBase
public sealed class ProjectActivity : ActivityBase {
public Project Project { get; private set; }
public ProjectActivity(Project project) {
Check.RequireNotNull<Project>(project);
Description = project.Description;
BusinessId = project.Code.ToString();
UniqueId = GetType().Name + " " + BusinessId;
Project = project;
}
}
这是我扔掉的初始数据库结构,在这里寻找反馈:
table Allocations (
AllocationID INT IDENTITY NOT NULL,
StartTime DATETIME NOT NULL,
EndTime DATETIME NOT NULL,
primary key (AllocationID)
foreign key (ActivityID)
foreign key (ResourceID)
)
table Activities (
ActivityID INT IDENTITY NOT NULL,
primary key (ActivityID)
ActivityType NVARCHAR(50) NOT NULL,
foreign key (WrappedActivityID) // for lack of a better name right now
)
table Projects ( // example of a WrappedActivity
ProjectID INT IDENTITY NOT NULL,
Prefix NVARCHAR(50) null,
Midfix NVARCHAR(50) null,
Sequence NVARCHAR(50) null,
Description NVARCHAR(50) null,
primary key (ProjectID)
)
table Resources (
ResourceID INT IDENTITY NOT NULL,
primary key (ResourceID)
ResourceType NVARCHAR(50) NOT NULL,
foreign key (WrappedResourceID)
)
table FullTimeStaffMembers ( // example of a WrappedResource
StaffMemberID INT IDENTITY NOT NULL,
Number NVARCHAR(50) not null unique,
FirstName NVARCHAR(50) not null,
LastName NVARCHAR(50) not null,
DepartmentID INT not null,
primary key (StaffMemberID)
)
我还没有为特定的继承映射方案(即每个类的表等)而努力,而是希望获得一个可以工作的起始数据库模型(即使不是最佳性能)。我已经痛苦地意识到,相比之下,数据库技能让我的编程技能看起来很棒,所以欢迎所有建设性的反馈和问题!
干杯,
贝里尔