支持的特性也相当多,除常规的CRUD+分页查询外,还包含以下特性:
1. 自定义存储过程的自动封装, 这样就不用额外写代码就可以完成自定义存储过程的调用了, 但是存储过程要以它规定的命名规则进行命名这样它才会识别出来.
2. 对索引列生成查询方法, 比如在用户表中经常给定用户名和密码这两个条件, 在这两个列上建立非聚集索引,那么.NetTiers将自动生成包含这两个条件的查询方法.
3.支持Deepload级联查询, 这个虽然效率不是很高,但在中小型的应用上还是相当方便地.
4. 使用Processor机制来完成一系列流程的连续调用,进行事务处理.
具体的使用方法可以参见园子里面其它人写的文章或官方文档,这里主要要讨论的是如果使用.NetTiers生成的东西.
我的办法是不直接使用它生成的解决方案,而是引用它编译之后的程序集,扩展部分的代码写在自己的工程中,从它生成的基类继承过来. 这样每将即使是要改库只需要将它生成的几个程序集签出来,重新运行CodeSmith生成代码后把编译出来的程序集拷贝过来覆盖掉再提交就OK了.
这时我们的Service层看起来可能是这个样子:
public class UsersFacade : UsersServiceBase { public UsersFacade() : base() { } public Users ValidateUser(string username, string password) { SqlFilterBuilder<UsersColumn> filter = new SqlFilterBuilder<UsersColumn>(); filter.Junction = SqlUtil.AND; filter.AppendEquals(UsersColumn.Name, username); filter.AppendEquals(UsersColumn.Password, password); int count = 0; TList<Users> users = DataRepository.UsersProvider.GetPaged(filter.ToString(), null, 0, 20, out count); if (users.Count > 0) return users[0]; else return null; } public Users ValidateUserAlter(string username, string password) { TList<Users> users = Find(string.Format("Name = '{0}' AND Password = '{1}'", username, password)); if (users != null && users.Count > 0) return users[0]; else return null; } public Users ValidateUserThird(string username, string password) { GB.Data.ParameterizedSqlFilterBuilder<Users> filter = new ParameterizedSqlFilterBuilder<Users>(); filter.AppendEquals("Name", "Darkangel"); filter.AppendEquals("Password", "5364241"); TList<Users> users = GB.Data.DataRepository.UsersProvider.Find(filter.GetParameters()); if (users != null && users.Count > 0) return users[0]; else return null; } } |
[TestFixture] public class SampleFixture { Users testUser = new Users(); [TestFixtureSetUp] public void Setup() { Users u = new Users(); u.Name = "Darkangel"; u.Password = "5364241"; u.UserId = IdentityGenerator.Instance.NextIdentity(); testUser.UserId = u.UserId; UsersFacade fa = new UsersFacade(); fa.Insert(u); } [TestFixtureTearDown] public void Clearup() { UsersFacade f = new UsersFacade(); f.Delete(testUser.UserId); } [Test] public void GetAllUserTest() { UsersFacade facade = new UsersFacade(); //TList<Users> list = facade.Find("Name='Darkangel'"); TList<Users> list = facade.GetAll(); Console.WriteLine("Toatal user acount is : " + list.Count); Assert.IsNotNull(list); Assert.IsTrue(list.Count > 0); } [Test] public void ValidateUserTest() { UsersFacade facade = new UsersFacade(); Users u = facade.ValidateUser("Darkangel", "5364241"); Assert.IsNotNull(u); Assert.IsTrue(u.UserId.Length > 0); } [Test] public void ValidateUserAlterTest() { UsersFacade facade = new UsersFacade(); Users u = facade.ValidateUserAlter("Darkangel", "5364241"); Assert.IsNotNull(u); Assert.IsTrue(u.UserId.Length > 0); } [Test] public void ValidateuserThirdTest() { UsersFacade facade = new UsersFacade(); Users u = facade.ValidateUserThird("Darkangel", "5364241"); Assert.IsNotNull(u); Assert.IsTrue(u.UserId.Length > 0); } } |