I m目前正在建立一个网络系统,并试图在SOA架构中实施N-Tier实体框架4.0和DTOs。 我对我如何实施数据获取、商业逻辑和列报方式有问题的理解。
让我们相信,我有一个“用户账户”实体,其内容如下:
Id
FirstName
尼亚美
审计领域——InsertDate
审计领域——最新情况
在“数字”中,我设立了“UserAccountsData.cs”类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrderSystemDAL
{
public static class UserAccountsData
{
public static int Insert(string firstName, string lastName, DateTime insertDate)
{
using (OrderSystemEntities db = new OrderSystemEntities())
{
return Insert(db, firstName, lastName, insertDate);
}
}
public static int Insert(OrderSystemEntities db, string firstName,
string lastName, DateTime insertDate)
{
return db.UserAccounts_Insert(firstName, lastName, insertDate, insertDate).ElementAt(0).Value;
}
public static void Update(int id, string firstName, string lastName,
DateTime updateDate)
{
using (OrderSystemEntities db = new OrderSystemEntities())
{
Update(db, id, firstName, lastName, updateDate);
}
}
public static void Update(OrderSystemEntities db, int id, string firstName,
string lastName, DateTime updateDate)
{
db.UserAccounts_Update(id, firstName, lastName, updateDate);
}
public static void Delete(int id)
{
using (OrderSystemEntities db = new OrderSystemEntities())
{
Delete(db, id);
}
}
public static void Delete(OrderSystemEntities db, int id)
{
db.UserAccounts_Delete(id);
}
public static UserAccount SelectById(int id)
{
using (OrderSystemEntities db = new OrderSystemEntities())
{
return SelectById(db, id);
}
}
public static UserAccount SelectById(OrderSystemEntities db, int id)
{
return db.UserAccounts_SelectById(id).ElementAtOrDefault(0);
}
public static List<UserAccount> SelectAll()
{
using (OrderSystemEntities db = new OrderSystemEntities())
{
return SelectAll(db);
}
}
public static List<UserAccount> SelectAll(OrderSystemEntities db)
{
return db.UserAccounts_SelectAll().ToList();
}
}
}
在《刑法》中,我设立了“UserAccountEO.cs”类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using OrderSystemDAL;
namespace OrderSystemBLL
{
public class UserAccountEO
{
public int Id { get; set; }
public string FirstName { get; set; }
public string 尼亚美 { get; set; }
public DateTime InsertDate { get; set; }
public DateTime UpdateDate { get; set; }
public string FullName
{
get
{
return 尼亚美 + ", " + FirstName;
}
}
public bool Save(ref ArrayList validationErrors)
{
ValidateSave(ref validationErrors);
if (validationErrors.Count == 0)
{
if (Id == 0)
{
Id = UserAccountsData.Insert(FirstName, 尼亚美, DateTime.Now);
}
else
{
UserAccountsData.Update(Id, FirstName, 尼亚美, DateTime.Now);
}
return true;
}
else
{
return false;
}
}
private void ValidateSave(ref ArrayList validationErrors)
{
if (FirstName.Trim() == "")
{
validationErrors.Add("The First Name is required.");
}
if (尼亚美.Trim() == "")
{
validationErrors.Add("The Last Name is required.");
}
}
public void Delete(ref ArrayList validationErrors)
{
ValidateDelete(ref validationErrors);
if (validationErrors.Count == 0)
{
UserAccountsData.Delete(Id);
}
}
private void ValidateDelete(ref ArrayList validationErrors)
{
//Check for referential integrity.
}
public bool Select(int id)
{
UserAccount userAccount = UserAccountsData.SelectById(id);
if (userAccount != null)
{
MapData(userAccount);
return true;
}
else
{
return false;
}
}
internal void MapData(UserAccount userAccount)
{
Id = userAccount.Id;
FirstName = userAccount.FristName;
尼亚美 = userAccount.尼亚美;
InsertDate = userAccount.审计领域——InsertDate;
UpdateDate = userAccount.审计领域——最新情况;
}
public static List<UserAccountEO> SelectAll()
{
List<UserAccountEO> userAccounts = new List<UserAccountEO>();
List<UserAccount> userAccountDTOs = UserAccountsData.SelectAll();
foreach (UserAccount userAccountDTO in userAccountDTOs)
{
UserAccountEO userAccountEO = new UserAccountEO();
userAccountEO.MapData(userAccountDTO);
userAccounts.Add(userAccountEO);
}
return userAccounts;
}
}
}
在《残疾人权利公约》中,我设立了以下网页:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OrderSystemBLL;
using System.Collections;
namespace OrderSystemUI
{
public partial class Users : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadUserDropDownList();
}
}
private void LoadUserDropDownList()
{
ddlUsers.DataSource = UserAccountEO.SelectAll();
ddlUsers.DataTextField = "FullName";
ddlUsers.DataValueField = "Id";
ddlUsers.DataBind();
}
}
}
采用EF4在一层建筑中采用多功能模型的正确方法吗?
I would appreciate your help Thanks.