<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://www.codeplex.com/rss.xsl"?><rss version="2.0"><channel><title>ASP.NET 2.0 ORM library. Save/Update/Load, native SQL queries Easy to start.</title><link>http://www.codeplex.com/easypersist/Project/ProjectRss.aspx</link><description>An ASP.NET Object Relational Mapping library.    Was inspired by Java Hibernate library, but more easy to start &amp;#38; use.   Very good for small &amp;#38; medium size projects.    Query objects with native SQL. Supp...</description><item><title>UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.&lt;br /&gt;&lt;br /&gt;...SQL Server 2005 Demo db added&lt;br /&gt;&lt;br /&gt;Some info about attached files&lt;br /&gt;&amp;#42; &amp;#42;EasyPersist.dll&amp;#42; -- is the compiled EasyPersist lib. If you don&amp;#39;t want to checkout the code you can just use this dll. Copy into bin folder for websites and add a refference in Visual Studio&lt;br /&gt;&amp;#42; &amp;#42;Core Demo Classes Project&amp;#42; -- is the &amp;#34;dll lib&amp;#34; project contains buissines classes fo the demo Site and Console Demo Projects. You don&amp;#39;t need it if you  just want to run the web or console demo it is also included in this projects as dll. But I recomend to look at it to understand the lib better.&lt;br /&gt;&amp;#42; &amp;#42;Web Site Demo&amp;#42; -- is the main demo I guess most of people are looking for. So it consists of 2 pages one lists the cities and the otehr is edit page which allows to add&amp;#47;edit a city. It inclides both dlls ORM and CoreClasses dll. More info here&amp;#58; &amp;#91;Web Demo Description&amp;#93;&lt;br /&gt;&amp;#42; &amp;#42;Console Demo Project&amp;#42; -- is a simple console app which shows how to work with the lib. It is very basik just a couple lines of code &amp;#58;&amp;#41;. More info is here&amp;#58; &amp;#91;Console Demo Description&amp;#93;&lt;br /&gt;&amp;#42; &amp;#42;Demo Database Bak SQL Server 2005&amp;#42; -- is the backup of the database with data for demo projects.  It is included in other zips so no need to download it as you already have it in Console or demo zips.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description><author></author><pubDate>Mon, 14 Apr 2008 15:19:23 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080414031923P</guid></item><item><title>UPDATED WIKI: Web Demo Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web Demo Description&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Website Demo
&lt;/h1&gt;I've created a simple project to show how to work with EasyPersist in the real life.&lt;br /&gt;The website consists of 2 pages and allows you to view the list of cities, add a city and edit a city.&lt;br /&gt; &lt;br /&gt;On edit page for Counties I use OpenSource project -- &lt;a href="http://convincingmail.com/autosuggest-autocomplete.aspx" class="externalLink"&gt;AJAX facebook like  Autocomplete control&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;also other opensource used:&lt;br /&gt;&lt;a href="http://www.prototypejs.org" class="externalLink"&gt;Prototypejs javascript framework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/AtlasControlToolkit" class="externalLink"&gt;AJAX Control Toolkit&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
How To Run
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Download &lt;b&gt;Web Site Demo&lt;/b&gt; from the Release Page&lt;/li&gt;&lt;li&gt;Unzip into IIS folder (usually c:\Inetpub\wwwroot\) The ZIP contains a folder with the site an SQL Struct and SQL Server 2005 DB bak. You need to restore the db backup in you SQL. &lt;/li&gt;&lt;li&gt;You can open website with Visual Studio and run it there or From IIS console create an application for the folder with the site files&lt;/li&gt;&lt;li&gt;Go to &lt;i&gt;your site root&lt;/i&gt;\App_Code\AppConfig.cs and edit Connection string &lt;/li&gt;&lt;li&gt;Open the site in the browser&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt; &lt;br /&gt;.....more info coming soon.... I'm ready to answer questions and provide some help ;)&lt;br /&gt; &lt;br /&gt;download the project sources from the release page&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Sat, 12 Apr 2008 08:34:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Web Demo Description 20080412083433A</guid></item><item><title>NEW POST: General</title><link>http://www.codeplex.com/easypersist/Thread/View.aspx?ThreadId=25809</link><description>&lt;div class="wikidoc"&gt;
Post your questions &amp;amp; suggestions here !&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Sat, 12 Apr 2008 07:35:21 GMT</pubDate><guid isPermaLink="false">NEW POST: General 20080412073521A</guid></item><item><title>UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.&lt;br /&gt;&lt;br /&gt;...SQL Server 2005 Demo db added</description><author></author><pubDate>Sat, 12 Apr 2008 07:33:54 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080412073354A</guid></item><item><title>UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.</description><author></author><pubDate>Sat, 12 Apr 2008 07:32:37 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080412073237A</guid></item><item><title>UPDATED WIKI: Web Demo Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web Demo Description&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Website Demo
&lt;/h1&gt;I've created a simple project to show how to work with EasyPersist in the real life.&lt;br /&gt;The website consists of 2 pages and allows you to view the list of cities, add a city and edit a city.&lt;br /&gt; &lt;br /&gt;On edit page for Counties I use OpenSource project -- &lt;a href="http://convincingmail.com/autosuggest-autocomplete.aspx" class="externalLink"&gt;AJAX facebook like  Autocomplete control&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;also other opensource used:&lt;br /&gt;&lt;a href="http://www.prototypejs.org" class="externalLink"&gt;Prototypejs javascript framework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/AtlasControlToolkit" class="externalLink"&gt;AJAX Control Toolkit&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;.....more info coming soon.... I'm ready to answer questions and provide some help ;)&lt;br /&gt; &lt;br /&gt;download the project sources from the release page&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Fri, 11 Apr 2008 12:40:57 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Web Demo Description 20080411124057P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=15</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM Framework Guide
&lt;/h1&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core%20Demo%20Classes%20Description&amp;amp;referringTitle=Home"&gt;Core Demo Classes Description&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Console Demo Description&lt;/a&gt; &lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Web Demo Description&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 21:18:08 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410091808P</guid></item><item><title>RELEASED: EasyPersist lib and Demo Projects (Apr 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.</description><author></author><pubDate>Thu, 10 Apr 2008 21:17:10 GMT</pubDate><guid isPermaLink="false">RELEASED: EasyPersist lib and Demo Projects (Apr 11, 2008) 20080410091710P</guid></item><item><title>UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.</description><author></author><pubDate>Thu, 10 Apr 2008 21:17:10 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080410091710P</guid></item><item><title>UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.</description><author></author><pubDate>Thu, 10 Apr 2008 21:15:38 GMT</pubDate><guid isPermaLink="false">UPDATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080410091538P</guid></item><item><title>CREATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008)</title><link>http://www.codeplex.com/easypersist/Release/ProjectReleases.aspx?ReleaseId=12467</link><description>There are no changes in the lib but I did changes in demo project.&lt;br /&gt;Also Core classes are now stored in their own project &amp;#40;dll&amp;#41;&lt;br /&gt;ANd added a web demo project.</description><author></author><pubDate>Thu, 10 Apr 2008 21:14:07 GMT</pubDate><guid isPermaLink="false">CREATED RELEASE: EasyPersist lib and Demo Projects (апр 11, 2008) 20080410091407P</guid></item><item><title>UPDATED WIKI: Console Demo Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console Demo Description&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Console Demo Project
&lt;/h1&gt; &lt;br /&gt;It is just a very simple project which shows how you can use the EasyPersist lib&lt;br /&gt; &lt;br /&gt;....more info is coming....&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 21:07:33 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Console Demo Description 20080410090733P</guid></item><item><title>UPDATED WIKI: Web Demo Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web Demo Description&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Website Demo
&lt;/h1&gt;I've created a simple project to show how to work with EasyPersist in the real life.&lt;br /&gt;The website consists of 2 pages and allows you to view the list of cities, add a city and edit a city.&lt;br /&gt; &lt;br /&gt;On edit page I use my other OpenSource project -- &lt;a href="http://convincingmail.com/autosuggest-autocomplete.aspx" class="externalLink"&gt;AJAX facebook like  Autocomplete control&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;also other opensource used:&lt;br /&gt;&lt;a href="http://www.prototypejs.org" class="externalLink"&gt;Prototypejs javascript framework&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/AtlasControlToolkit" class="externalLink"&gt;AJAX Control Toolkit&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;.....more info coming soon.... I'm ready to answer questions and provide some help ;)&lt;br /&gt; &lt;br /&gt;download the project sources from the release page&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 21:04:59 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Web Demo Description 20080410090459P</guid></item><item><title>UPDATED WIKI: Core Demo Classes Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core Demo Classes Description&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Demo Classes Project
&lt;/h1&gt;This project contains buissines classes I use in web demo project and console demo project. (see: &lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo%20Description&amp;amp;referringTitle=Core%20Demo%20Classes%20Description"&gt;Console Demo Description&lt;/a&gt;  and &lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo%20Description&amp;amp;referringTitle=Core%20Demo%20Classes%20Description"&gt;Web Demo Description&lt;/a&gt;) &lt;br /&gt;The project contains of 3 classes which represent the persistent buissiness classes of the solution.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;City&lt;/li&gt;&lt;li&gt;County&lt;/li&gt;&lt;li&gt;State&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The structure is very simple and self-descriptive.&lt;br /&gt; &lt;br /&gt;You can download from the release page.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:58:02 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Core Demo Classes Description 20080410085802P</guid></item><item><title>UPDATED WIKI: Core Demo Classes Description</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core Demo Classes Description&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Demo Classes Project
&lt;/h1&gt;This project contains buissines classes I use in web demo project and console demo project. (see: &lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo%20Description&amp;amp;referringTitle=Core%20Demo%20Classes%20Description"&gt;Console Demo Description&lt;/a&gt;  and &lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core%20Demo%20Classes%20Description&amp;amp;referringTitle=Core%20Demo%20Classes%20Description"&gt;Core Demo Classes Description&lt;/a&gt;) &lt;br /&gt;The project contains of 3 classes which represent the persistent buissiness classes of the solution.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;City&lt;/li&gt;&lt;li&gt;County&lt;/li&gt;&lt;li&gt;State&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The structure is very simple and self-descriptive.&lt;br /&gt; &lt;br /&gt;You can download from the release page.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:57:27 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Core Demo Classes Description 20080410085727P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=14</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM Framework Guide
&lt;/h1&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core%20Demo%20Classes%20Description&amp;amp;referringTitle=Home"&gt;Core Demo Classes Description&lt;/a&gt; (Load project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=31992';"&gt;Core Demo Classes&lt;/a&gt;)&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Console Demo Description&lt;/a&gt; (Load project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=31993';"&gt;Console Demo Project&lt;/a&gt;)&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Web Demo Description&lt;/a&gt; (Load project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=31991';"&gt;Web Demo Project&lt;/a&gt;)&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:50:24 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410085024P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=13</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM Framework Guide
&lt;/h1&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Core%20Demo%20Classes%20Description&amp;amp;referringTitle=Home"&gt;Core Demo Classes Description&lt;/a&gt; (Load project: &lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[file:Core Demo Classes|EasyPersistWebDemo.zip])&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Console Demo Description&lt;/a&gt; (Load project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=31993';"&gt;Console Demo Project&lt;/a&gt;)&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo%20Description&amp;amp;referringTitle=Home"&gt;Web Demo Description&lt;/a&gt; (Load project: &lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[file:Web Demo Project|EasyPersistWebDemo.zip])&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:49:34 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410084934P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=12</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM Framework Guide
&lt;/h1&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo&amp;amp;referringTitle=Home"&gt;Console Demo&lt;/a&gt; (Load demo project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=30257';"&gt;Console Demo Project&lt;/a&gt;)&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo&amp;amp;referringTitle=Home"&gt;Web Demo&lt;/a&gt; (Load demo project: &lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[file:Console Demo Project|EasyPersistWebDemo.zip])&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:19:28 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410081928P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=11</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM lib Quick Start Guide
&lt;/h1&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo&amp;amp;referringTitle=Home"&gt;Console Demo&lt;/a&gt; (Load demo project: &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=30257';"&gt;Console Demo Project&lt;/a&gt;)&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo&amp;amp;referringTitle=Home"&gt;Web Demo&lt;/a&gt; (Load demo project: &lt;span class="unresolved"&gt;Cannot resolve link: &lt;/span&gt;[file:Console Demo Project|EasyPersistWebDemo.zip])&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:18:28 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410081828P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Home&amp;version=10</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
EasyPersist ORM lib Quick Start Guide
&lt;/h1&gt; &lt;br /&gt;Load demo project:&lt;br /&gt;&lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=easypersist&amp;amp;DownloadId=30257';"&gt;Demo Project&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Contents
&lt;/h2&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Console%20Demo&amp;amp;referringTitle=Home"&gt;Console Demo&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/easypersist/Wiki/View.aspx?title=Web%20Demo&amp;amp;referringTitle=Home"&gt;Web Demo&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Quick Start Guide
&lt;/h2&gt; &lt;br /&gt;EasyPersist  ORM lib is used to simplify Loading and Saving objects in SQL Server. The lib uses native SQL to query db.&lt;br /&gt;Core functionality includes:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Save/Update object in DB&lt;/li&gt;&lt;li&gt;Load objects from DB&lt;/li&gt;&lt;li&gt;Load lists of objects from DB&lt;/li&gt;&lt;li&gt;Delete object from DB&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;The mapping mechanism is very simple. Done via attributes (no complex xml etc.).&lt;br /&gt; &lt;br /&gt;There are two ways to use it &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;Load/Save “Persistent” object in db.&lt;/li&gt;&lt;li&gt;Load “Read-only” object from db.&lt;/li&gt;
&lt;/ol&gt; &lt;br /&gt;&lt;h2&gt;
ReadOnly Classes
&lt;/h2&gt;Used in situation when you need to quickly load custom data and don’t want to save it back in db.  Very useful when you already have data layer but want to use the lib to simplify loading of objects.&lt;br /&gt; &lt;br /&gt;So first of all you need a class to work with.&lt;br /&gt; &lt;br /&gt;LocationHelper class is: &lt;br /&gt;&lt;pre&gt;
    using System.Data;
using Loc.HibernateMini.Attributes;
 
namespace EasyPersistDemo {
    public class TestLocation {
        private int _id;
        private string _city;
        private string _county;
        private string _state;
        
        [PersistentProperty(&amp;quot;LocCityId&amp;quot;, DbType.Int32)]
        public int Id {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;CityName&amp;quot;, DbType.String)]
        public string City {
            get { return _city; }
            set { _city = value; }
        }
        [PersistentProperty(&amp;quot;CountyName&amp;quot;, DbType.String)]
        public string County {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;StateName&amp;quot;, DbType.String)]
        public string State {
            get { return _state; }
            set { _state = value; }
        }
        public override string ToString()
        {
            return City + &amp;quot;, &amp;quot; + County + &amp;quot;, &amp;quot; + State;
        }
        public string CityCaps {
            get { return _city.ToUpper(); }
        }
    }
}
&lt;/pre&gt; &lt;br /&gt;The lib will take this TestLocation, loop thru properties marked with PersistentProperty attribute and set their values from the dataset. Note that CityCaps property is not marked with PersistentProperty Attribute. It encapsulates some business logic and should not be bind/loaded with data. (Attribute first param is the column name in sql query)&lt;br /&gt; &lt;br /&gt;Ok now you can load data from db&lt;br /&gt;&lt;pre&gt;
string locationSql = @&amp;quot;
SELECT City.CityId as LocCityId, City.Name as CityName, County.Name as CountyName, State.Name as StateName
FROM City 
INNER JOIN County ON City.CountyId=County.CountyId
INNER JOIN State ON County.StateId=State.StateId
ORDER BY City.Name, County.Name, State.Name
&amp;quot;;
            ArrayList locations = program.Dao.GetReadOnlyListFromDb(new SqlCommand(locationSql), typeof(TestLocation));
            foreach (TestLocation location in locations)
            {
                Console.WriteLine(location.ToString());
            }
&lt;/pre&gt; &lt;br /&gt;Very easy. All you need is a sql query (column names should be the same as defined in TestLocation property attributes). And call GetReadOnlyListFromDb method:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
_dao.GetReadOnlyListFromDb(sqlCommand, typeof(TestLocation));
&lt;/pre&gt; &lt;br /&gt;It returns a list of objects of type TestLocation.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
“Persistent” classes
&lt;/h2&gt;Persistent is the the class which is reflected by db table and could be loaded and saved in db.&lt;br /&gt;“Persistent” classes are the core of your application and the data layer. Persistent class is marked with PersistentClass Attribute and implements IPersistent interface. &lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
[PersistentClass(&amp;quot;City&amp;quot;)]
 public class City: IPersistent {
&lt;/pre&gt; &lt;br /&gt;There should be an Id property required by interface&lt;br /&gt;&lt;pre&gt;
[PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
public int Id {
   get { return _id; }
   set { _id = value; }
}
&lt;/pre&gt; &lt;br /&gt;All properties which should be saved in db are marked with PersistentProperty attribute&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
using System;
using System.Data;
using Loc.HibernateMini.Attributes;
using Loc.HibernateMini.IFaces;
 
namespace EasyPersistDemo.Core {
    [PersistentClass(&amp;quot;City&amp;quot;)]
    public class City : IPersistent {
        //ID of the city (required to identify a record in db. usually it is identity column)
        private int _id;
        //name of the city (just a textual property)
        private string _name;
        // nullable DateTime property
        private DateTime? _changeDate; 
        //boolean property
        private bool _isActive; 
        //Enum property (maps to int in db)
        private SettlementType _type; 
        //Persistent object (many-to-one)
        private County _county; 
        
        [PersistentProperty(&amp;quot;CityId&amp;quot;, DbType.Int32)]
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [PersistentProperty(&amp;quot;Name&amp;quot;, DbType.String)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        [PersistentProperty(&amp;quot;ChangeDate&amp;quot;, DbType.DateTime)]
        public DateTime? ChangeDate
        {
            get { return _changeDate; }
            set { _changeDate = value; }
        }
        [PersistentProperty(&amp;quot;IsActive&amp;quot;, DbType.Boolean)]
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }
        [PersistentProperty(&amp;quot;CountyId&amp;quot;)]
        public County County
        {
            get { return _county; }
            set { _county = value; }
        }
        [PersistentProperty(&amp;quot;SettlementType&amp;quot;, DbType.Int32)]
        public SettlementType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    }
    public enum SettlementType
    {
        Hamlet,Village,Town,City,Megalopolis 
    }
}
&lt;/pre&gt; &lt;br /&gt;How to save a new City:&lt;br /&gt;&lt;pre&gt;
   City city = new City();
                    city.Name = &amp;quot;Jacksonville&amp;quot;;
                    city.ChangeDate = DateTime.Now;
                    city.IsActive = true;
                    city.Type = SettlementType.City;
                    city.County = county;
                    _dao.SaveOrUpdate(city);
                    Console.WriteLine(&amp;quot;Saved City &amp;quot; + city.Name + &amp;quot; ID:&amp;quot; + city.Id);
&lt;/pre&gt;All you need is to create the new instance of City, set properties and call _dao.SaveOrUpdate(City);&lt;br /&gt; &lt;br /&gt;The lib will look an Id (via IPersistent interface) and if it is 0 a new City will be created (INSERT stetement) else the lib will generate an UPDATE sql and the row will be updated.&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [City] ( [Name], [ChangeDate], [IsActive], [CountyId], [SettlementType] ) 
VALUES ( @Name, @ChangeDate, @IsActive, @CountyId, @SettlementType ); select scope_identity()
&lt;/pre&gt; &lt;br /&gt; &lt;br /&gt;The lib prints all db calls in Debug out so you can see all db calls&lt;br /&gt;e.g.:&lt;br /&gt;&lt;pre&gt;
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
INSERT INTO [State] ( [Name] ) VALUES ( @Name ); select scope_identity()
UPDATE [State] SET [Name]=@Name WHERE [State].[StateId]=2
Loading List SQL:SELECT top 1 * FROM State WHERE State.Name = @name
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
INSERT INTO [County] ( [Name], [StateId] ) VALUES ( @Name, @StateId ); select scope_identity()
Loading List SQL:SELECT * FROM County
&lt;/pre&gt; &lt;br /&gt;Note that the lib caches objects.&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Use CsUnit to run tests&lt;br /&gt;&lt;a href="http://www.csUnit.org" class="externalLink"&gt;http://www.csUnit.org&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;And unitRun plug-in may be also helpful&lt;br /&gt;&lt;a href="http://www.jetbrains.com/unitrun/" class="externalLink"&gt;http://www.jetbrains.com/unitrun/&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt; &lt;br /&gt;Thanks.&lt;br /&gt;
&lt;/div&gt;</description><author>trooper</author><pubDate>Thu, 10 Apr 2008 20:17:22 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20080410081722P</guid></item></channel></rss>