NHibernate
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
#contents
http://wiki.nhibernate.org/display/NH/Home
http://sourceforge.net/project/showfiles.php?group_id=73818
*Quick Start [#zee5d2d5]
use NHibernate
go
CREATE TABLE users (
LogonID nvarchar(20) NOT NULL default '0',
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go
using System;
namespace NHibernate.Examples.QuickStart
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
{
}
public string Id
{
get { return id; }
set { id = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.QuickStart.User, NHibe...
<id name="Id" column="LogonID" type="String" length="2...
<generator class="assigned" />
</id>
<property name="UserName" column= "Name" type="String"...
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40...
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
&ref(BuildAction.PNG);
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler...
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvi...
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;initial catalog=nhibernate...
/>
</nhibernate>
</configuration>
**Insert [#uc096933]
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;
session.Save(newUser);
transaction.Commit();
session.Close();
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
IList userList = session.CreateCriteria(typeof(User)).Li...
session.Close();
foreach(User user in userList)
{
System.Diagnostics.Debug.WriteLine(user.Id + ":" +user....
}
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
IList recentUsers = session.CreateCriteria(typeof(User))
.Add(Expression.Expression.Gt("LastLogon", new DateT...
.List();
session.Close();
foreach(User user in userList)
{
System.Diagnostics.Debug.WriteLine(user.Id + ":" +user....
}
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User joeCool = (User)session.Load(typeof(User), "joe_coo...
joeCool.LastLogon = DateTime.Now;
session.Flush();
transaction.Commit();
session.Close();
--1側
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" au...
<class name="SsttIssue" table="SSTT_ISSUE">
<composite-id>
<key-property name="CompanyCd" type="String" >
<column name="COMPANY_CD" />
</key-property>
<key-property name="IssueNo" type="String" >
<column name="ISSUE_NO" />
</key-property>
</composite-id>
<property column="ISSUE_KBN" type="String" name="Issue...
<property column="STAT_KBN" type="String" name="StatKb...
<property column="ISSUE_OUTLINE" type="String" name="I...
<property column="ISSUE_OUTLINE_02" type="String" name...
<property column="LOCK_TIME" type="DateTime" name="Loc...
<property column="LOCK_SUID" type="Decimal" name="Lock...
<property column="TICKET_ID" type="String" name="Ticke...
<property column="DEL_FLG" type="String" name="DelFlg"...
<property column="INS_SUID" type="Decimal" name="InsSu...
<property column="INS_DATE" type="DateTime" name="InsD...
<property column="UPD_SUID" type="Decimal" name="UpdSu...
<property column="UPD_DATE" type="DateTime" name="UpdD...
<bag name="ssrtIssueRela">
<key>
<column name="ISSUE_NO" />
</key>
<one-to-many class="SsrtIssueRela" />
</bag>
</class>
</hibernate-mapping>
--多側
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" au...
<class name="SsrtIssueRela" table="SSRT_ISSUE_RELA">
<composite-id>
<key-property name="IssueCompanyCd" type="String" >
<column name="ISSUE_COMPANY_CD" />
</key-property>
<key-property name="IssueNo" type="String" >
<column name="ISSUE_NO" />
</key-property>
<key-property name="BusinessTrnCompanyCd" type="Strin...
<column name="BUSINESS_TRN_COMPANY_CD" />
</key-property>
<key-property name="BusinessTrnKbn" type="String" >
<column name="BUSINESS_TRN_KBN" />
</key-property>
<key-property name="BusinessTrnNo" type="String" >
<column name="BUSINESS_TRN_NO" />
</key-property>
</composite-id>
<property column="INS_SUID" type="Decimal" name="InsSu...
<property column="INS_DATE" type="DateTime" name="InsD...
<property column="UPD_SUID" type="Decimal" name="UpdSu...
<property column="UPD_DATE" type="DateTime" name="UpdD...
<many-to-one name="ssttIssue" class="SsttIssue">
<column name="ISSUE_NO" />
</many-to-one>
</class>
</hibernate-mapping>
終了行:
#contents
http://wiki.nhibernate.org/display/NH/Home
http://sourceforge.net/project/showfiles.php?group_id=73818
*Quick Start [#zee5d2d5]
use NHibernate
go
CREATE TABLE users (
LogonID nvarchar(20) NOT NULL default '0',
Name nvarchar(40) default NULL,
Password nvarchar(20) default NULL,
EmailAddress nvarchar(40) default NULL,
LastLogon datetime default NULL,
PRIMARY KEY (LogonID)
)
go
using System;
namespace NHibernate.Examples.QuickStart
{
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
private DateTime lastLogon;
public User()
{
}
public string Id
{
get { return id; }
set { id = value; }
}
public string UserName
{
get { return userName; }
set { userName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public DateTime LastLogon
{
get { return lastLogon; }
set { lastLogon = value; }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.QuickStart.User, NHibe...
<id name="Id" column="LogonID" type="String" length="2...
<generator class="assigned" />
</id>
<property name="UserName" column= "Name" type="String"...
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40...
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
&ref(BuildAction.PNG);
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler...
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvi...
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;initial catalog=nhibernate...
/>
</nhibernate>
</configuration>
**Insert [#uc096933]
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User newUser = new User();
newUser.Id = "joe_cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;
session.Save(newUser);
transaction.Commit();
session.Close();
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
IList userList = session.CreateCriteria(typeof(User)).Li...
session.Close();
foreach(User user in userList)
{
System.Diagnostics.Debug.WriteLine(user.Id + ":" +user....
}
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
IList recentUsers = session.CreateCriteria(typeof(User))
.Add(Expression.Expression.Gt("LastLogon", new DateT...
.List();
session.Close();
foreach(User user in userList)
{
System.Diagnostics.Debug.WriteLine(user.Id + ":" +user....
}
using NHibernate;
using NHibernate.Cfg;
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
User joeCool = (User)session.Load(typeof(User), "joe_coo...
joeCool.LastLogon = DateTime.Now;
session.Flush();
transaction.Commit();
session.Close();
--1側
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" au...
<class name="SsttIssue" table="SSTT_ISSUE">
<composite-id>
<key-property name="CompanyCd" type="String" >
<column name="COMPANY_CD" />
</key-property>
<key-property name="IssueNo" type="String" >
<column name="ISSUE_NO" />
</key-property>
</composite-id>
<property column="ISSUE_KBN" type="String" name="Issue...
<property column="STAT_KBN" type="String" name="StatKb...
<property column="ISSUE_OUTLINE" type="String" name="I...
<property column="ISSUE_OUTLINE_02" type="String" name...
<property column="LOCK_TIME" type="DateTime" name="Loc...
<property column="LOCK_SUID" type="Decimal" name="Lock...
<property column="TICKET_ID" type="String" name="Ticke...
<property column="DEL_FLG" type="String" name="DelFlg"...
<property column="INS_SUID" type="Decimal" name="InsSu...
<property column="INS_DATE" type="DateTime" name="InsD...
<property column="UPD_SUID" type="Decimal" name="UpdSu...
<property column="UPD_DATE" type="DateTime" name="UpdD...
<bag name="ssrtIssueRela">
<key>
<column name="ISSUE_NO" />
</key>
<one-to-many class="SsrtIssueRela" />
</bag>
</class>
</hibernate-mapping>
--多側
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" au...
<class name="SsrtIssueRela" table="SSRT_ISSUE_RELA">
<composite-id>
<key-property name="IssueCompanyCd" type="String" >
<column name="ISSUE_COMPANY_CD" />
</key-property>
<key-property name="IssueNo" type="String" >
<column name="ISSUE_NO" />
</key-property>
<key-property name="BusinessTrnCompanyCd" type="Strin...
<column name="BUSINESS_TRN_COMPANY_CD" />
</key-property>
<key-property name="BusinessTrnKbn" type="String" >
<column name="BUSINESS_TRN_KBN" />
</key-property>
<key-property name="BusinessTrnNo" type="String" >
<column name="BUSINESS_TRN_NO" />
</key-property>
</composite-id>
<property column="INS_SUID" type="Decimal" name="InsSu...
<property column="INS_DATE" type="DateTime" name="InsD...
<property column="UPD_SUID" type="Decimal" name="UpdSu...
<property column="UPD_DATE" type="DateTime" name="UpdD...
<many-to-one name="ssttIssue" class="SsttIssue">
<column name="ISSUE_NO" />
</many-to-one>
</class>
</hibernate-mapping>
ページ名: