【发布时间】:2011-01-22 02:22:23
【问题描述】:
应该将域实体公开为接口还是普通对象?
用户界面:
public interface IUser
{
string FirstName { get; set; }
string LastName { get; set; }
string Email { get; set; }
Role Role { get; set; }
}
用户实现(实现到 LinqToSql 数据访问层):
public class User : IUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public Role Role { get; set; }
}
用户实现(在 NHibernate 数据访问层中实现):
[NHibernate.Mapping.Attributes.Class]
public class User : IUser
{
[NHibernate.Mapping.Attributes.Property]
public string FirstName { get; set; }
[NHibernate.Mapping.Attributes.Property]
public string LastName { get; set; }
[NHibernate.Mapping.Attributes.Property]
public string Email { get; set; }
[NHibernate.Mapping.Attributes.Property]
public Role Role { get; set; }
}
这只是说明了一些 DAL 特定的实现,目前没有更好的示例。
【问题讨论】: