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
  • 相关阅读:
    UART协议
    芯片时钟体系(take example as s3c2440)
    PCIe协议
    I2C协议
    SPI协议
    嵌入式相关术语列表
    TreeView控件数据绑定之:数据库数据递归绑定
    连接SQL Server 数据库的三种方式
    JS小功能之:五角星评论
    MVC学习之开发技巧总结(1)
  • 原文地址:https://www.cnblogs.com/silva/p/1583326.html
Copyright © 2011-2022 走看看