惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
Intezer
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
N
News | PayPal Newsroom
T
Tenable Blog
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
P
Privacy International News Feed
IT之家
IT之家
Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
博客园_首页
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
NISL@THU
NISL@THU
I
InfoQ
D
DataBreaches.Net
有赞技术团队
有赞技术团队
K
Kaspersky official blog
Security Latest
Security Latest
The Register - Security
The Register - Security
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
P
Proofpoint News Feed
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic

博客园 - henry

Smark.Net.Tcp.XmlService性能测试程序 基于Flex的http简易文件管理工具 性能的瓶颈到底在那呢? 运用Smark.SocketAsyncs扩展基于XML的TCP服务 运用Smark.SocketAsyncs方便实现数据交互服务 实现分布式对象锁 发布一个C#实现的Asterisk的管理系统 asterisk使用SIP相互对接 开源一个基于Flex4+C#的个人信息管理程序 FlashBuilder4试用 这样的重构是否有必要呢? Asterisk2B用户管理逻辑设计 用JQuery UI dialog实现Alert和Confirm功能 - henry Asterisk发起电话预约回拔 WOW工会DKP管理系统 我的分页控件设计 实现一个JavaScript验证的Asp.net Helper - henry - 博客园 Smark.Data 实体属性值描述 Smark.Data实体成员数据验证
Smark.Data Part1
henry · 2009-09-15 · via 博客园 - henry

       这一章主要介绍一下如何使用Smark.Data组件进行数据库操作;让使用者了简单了解一下Smark.Data的配置、实体类配置和简单的操作。在使用组件时程序必须引用Smark.CoreSmark.Data两个组件;其源代码可以到:http://smark.codeplex.com/下载。为了方便范例所使用的数据是Northwind.mdb.

l        配置文件设置:

  <configSections>

    <section  name="smarkdata" type="Smark.Data.SmarkDataSection,Smark.Data"/>

  </configSections>

  <smarkdata>

    <Connection>

      <add name="0" type="Smark.Data.MSAccess,Smark.Data" connectionstring=""/>

    </Connection>

    <Assembly>

      <add type="Smark.Samples.Entities"/>

    </Assembly>

</smarkdata>

l        实体类创建

实体类是通过自定义工具,把相关接口代码生成类代码;所以必须安装Smark.Data.InterfaceToModelGenerator

创建Entities.cs文件->文件属性的:InterfaceToModel

    [Table("Employees")]

    interface IEmployee

    {

        [ID]

        [IDENTITY]

        int EmployeeID { get; set; }

        [Column]

        string LastName { get; set; }

        [Column]

        string FirstName { get; set; }

        [Column]

        string Title { get; set; }

        [Column]

        string TitleOfCourtesy { get; set; }

        [Column]

        DateTime BirthDate { get; set; }

        [Column]

        DateTime HireDate { get; set; }

        [Column]

        string Address { get; set; }

        [Column]

        string City { get; set; }

        [Column]

        string Region { get; set; }

        [Column]

        string PostalCode { get; set; }

        [Column]

        string Country { get; set; }

        [Column]

        string HomePhone { get; set; }

        [Column]

        string Extension { get; set; }

        [Column]

        string Photo { get; set; }

        [Column]

        string Notes { get; set; }

        [Column]

        int ReportsTo { get; set; }

 }

InterfaceToModelGenerator会根据接口文件生成实体文件

    [Table("Employees")]

     [Serializable]

    public partial class Employee:Smark.Data.Mappings.DataObject,IEmployee

    {

        [ID]

        [IDENTITY]

        public int EmployeeID { get{ return mEmployeeID;} set{mEmployeeID=value;EntityState.FieldChange("EmployeeID");} }

         private int mEmployeeID;

         public static Smark.Data.FieldInfo employeeID = new Smark.Data.FieldInfo("Employees","EmployeeID");

        [Column]

        public string LastName { get{ return mLastName;} set{mLastName=value;EntityState.FieldChange("LastName");} }

         private string mLastName;

         public static Smark.Data.FieldInfo lastName = new Smark.Data.FieldInfo("Employees","LastName");

        [Column]

        public string FirstName { get{ return mFirstName;} set{mFirstName=value;EntityState.FieldChange("FirstName");} }

         private string mFirstName;

         public static Smark.Data.FieldInfo firstName = new Smark.Data.FieldInfo("Employees","FirstName");

        [Column]

        public string Title { get{ return mTitle;} set{mTitle=value;EntityState.FieldChange("Title");} }

         private string mTitle;

         public static Smark.Data.FieldInfo title = new Smark.Data.FieldInfo("Employees","Title");

        [Column]

        public string TitleOfCourtesy { get{ return mTitleOfCourtesy;} set{mTitleOfCourtesy=value;EntityState.FieldChange("TitleOfCourtesy");} }

         private string mTitleOfCourtesy;

         public static Smark.Data.FieldInfo titleOfCourtesy = new Smark.Data.FieldInfo("Employees","TitleOfCourtesy");

l        数据库操作

            DBContext.SetConnectionString(ConnectionType.Context1, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=http://www.cnblogs.com/Northwind.mdb");

            Employee emp = DBContext.Load<Employee>(3);

            Console.WriteLine(emp.FirstName + "\t" + emp.LastName);

            Console.WriteLine(emp.Country);

            emp.Country = emp.Country + "Change";

            DBContext.Save(emp);

            emp = new Employee();

            emp.FirstName = "henry";

            emp.LastName = "Fan";

            DBContext.Save(emp);

范例详细代码:

http://smark.codeplex.com/源代码的Samples目录下。