zoukankan      html  css  js  c++  java
  • Talk O/RM (DAL) too ...

    如何把数据库中的关系转换为对象,如何把对对象的操作进行持久化保存?

    不仅仅为了节省大量工作量,而且更重要的是,the above layer should just know Business Object, not Data Table in database.


    下面是一些实践.

    0. 纯手工劳动. 用上SqlHelper\Enterprise Library DAAB, 自己建类以及数据库操作方法代码.  还有CodeSmith代码生成器.

    1. 起初,我们用强类型的DataSet. We can use Strongly Typed TableAdapters and DataTables in VS.Net 2005
    Scott said: It is pretty useful and flexible.  I really like the fact that it enables me to avoid having to write tedious data access code.

    2. Microsoft LINQ to SQL -- .Net 下的ORM解决方案

    转载一篇很好的文章.

    Code

    add record to db: InsertOnSubmit, InsertAllOnSubmit

    Linq分页. 由于是延迟执行,直到.toList()执行的时候才执行具体的sql语句.. 所以,可以利用Linq做大数据量的分页解决方案.

    var pagedC1 = (from c1 in db.Customers select c1).Skip(20).Take(10);
    var arrayC1 
    = pagedC1.ToList();


    跟踪sql server Profiler,生成的sql语句为:
    exec sp_executesql N'SELECT [t1].[CustomerID], [t1].[CompanyName], [t1].[ContactName], [t1].[ContactTitle], [t1].[Address], [t1].[City], [t1].[Region], [t1].[PostalCode], [t1].[Country], [t1].[Phone], [t1].[Fax]
    FROM (
        SELECT ROW_NUMBER() OVER (ORDER BY [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]) AS [ROW_NUMBER], [t0].[CustomerID],
    [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]
        FROM [dbo].[Customers] AS [t0]
        ) AS [t1]
    WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + 1 AND @p0 + @p1
    ORDER BY [t1].[ROW_NUMBER]
    ',N'@p0 int,@p1 int',@p0=20,@p1=10


    3. Entity Framework

    4. 另外,还有NHibernate或者SubSonic
  • 相关阅读:
    oracle的commit
    struts2 Action 接收参数的三种方法
    git -速查表
    Windows 手动创建 服务
    Linux 上 安装 composer
    Class文件解析
    Java 从数据库中查找信息导入Excel表格中
    将Java Web项目部署到远程主机上
    Java8 map和reduce
    group By 和 Union 、 Union all的用法
  • 原文地址:https://www.cnblogs.com/silva/p/1583326.html
Copyright © 2011-2022 走看看