|
using System;
using System.Collections.Generic;
using System.Text;
using Shared.NHibernateDAL;
using NHibernate;
namespace Business
{
public class Product : BusinessObject<Product>
{
public Product()
{
this._name = null;
this._weight = 0;
}
private string _name;
private decimal _weight;
public virtual decimal Weight
{
get { return _weight; }
set { _weight = value; }
}
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
public static List<Product> Select()
{
ISession session = NHibernateSessionManager.Instance.GetSession();
IQuery query = session.CreateQuery("from Product");
return (List<Product>)query.List<Product>();
}
public void OutterTransaction()
{
using (TransactionBlock tran = new TransactionBlock())
{
Product p1 = new Product();
p1.Name = "Product 1";
p1.Weight = 10;
p1.Save();
//Call another method with a transaction block
InnerTransaction();
tran.IsValid = true;
// On the dispose call the transaction is commited if all transaction blocks are valid
}
}
private void InnerTransaction()
{
using (TransactionBlock tran = new TransactionBlock())
{
Product p2 = new Product();
p2.Name = "Product 2";
p2.Weight = 10;
p2.Save();
tran.IsValid = true;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I've been developing .NET enterprise applications since 2000.
I am originally from Rio de Janeiro and I am currently working at http://www.intelligentcoder.com in Ontario.
I also have my own startup where we offer
client intake forms.