110,499
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;
using NUnit.Framework;
namespace NHibernateTest
{
[TestFixture]
public class NHibernateInit
{
public void InitTest()
{
var cfg = new NHibernate.Cfg.Configuration().Configure(System.AppDomain.CurrentDomain.BaseDirectory + "\\Config\\hibernate.cfg.xml");
using (ISessionFactory sessionFactory = cfg.BuildSessionFactory()) { }
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
This template was written to work with NHibernate.Test.
Copy the template to your NHibernate.Test project folder and rename it in hibernate.cfg.xml and change it
for your own use before compile tests in VisualStudio.
-->
<!-- This is the System.Data.dll provider for SQL Server -->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Server=.;initial catalog=NHibernateDemo;uid=sa;pwd=abao_yatou
</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="show_sql">true</property>
<!--指定用ADO.NET的批量更新的数量-->
<property name="adonet.batch_size">10</property>
<!--指定NHibernate生产的IDbCommands对象的超时时间-->
<property name="command_timeout">60</property>
<!--将Nhibernate查询中的符号映射到SQL查询中的符号-->
<property name="query.substitutions">true 1,false 0,yes 'Y',no 'N'</property>
<mapping assembly="Domain"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain" namespace="Domain">
<class name="Product" table="T_Product" lazy="true">
<id name="ID" column="ID">
<generator class="assigned"></generator>
</id>
<property name="Code" column="Code" type="String" length="50"></property>
<property name="Name" type="String" column="Name" length="50"></property>
<property name="QuantityPerUnit" type="String" column="QuantityPerUnit" length="50"></property>
<property name="Unit" type="String" column="Unit" length="50"></property>
<property name="SellPrice" type="decimal" column="SellPrice" precision="14" scale="2"></property>
<property name="BuyPrice" type="decimal" column="BuyPrice" precision="14" scale="2"></property>
<property name="Remark" type="String" column="Remark" length="200"></property>
</class>
</hibernate-mapping>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Domain
{
/// <summary>
/// 商品
/// </summary>
public class Product
{
/// <summary>
/// ID
/// </summary>
public virtual Guid ID { get; set; }
/// <summary>
/// 编号
/// </summary>
public virtual string Code { get; set; }
/// <summary>
/// 名称
/// </summary>
public virtual string Name { get; set; }
/// <summary>
/// 规格
/// </summary>
public virtual string QuantityPerUnit { get; set; }
/// <summary>
/// 单位
/// </summary>
public virtual string Unit { get; set; }
/// <summary>
/// 售价
/// </summary>
public virtual decimal SellPrice { get; set; }
/// <summary>
/// 进价
/// </summary>
public virtual decimal BuyPrice { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string Remark { get; set; }
}
}
if exists (select * from dbo.sysobjects where id = object_id(N'T_Product') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table T_Product
create table T_Product (
ID UNIQUEIDENTIFIER not null,
Code NVARCHAR(50) null,
Name NVARCHAR(50) null,
QuantityPerUnit NVARCHAR(50) null,
Unit NVARCHAR(50) null,
SellPrice DECIMAL(14, 2) null,
BuyPrice DECIMAL(14, 2) null,
Remark NVARCHAR(200) null,
primary key (ID)
)