Wednesday, March 3, 2010

NHibernate

Quickstart guide

1. Create db nhibernate
2. Create table users
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

3. Create the test windows forms app, add the user class
public class User{
private string id, userName, password, emailAddress;
private DateTime lastLogon;

public virtual string Id{
get { return id; }
set { id = value; }
}
public virtual string UserName{
get { return userName; }
set { userName = value; }
}
public virtual string Password{
get { return password; }
set { password = value; }
}
public virtual string EmailAddress{
get { return emailAddress; }
set { emailAddress = value; }
}
public virtual DateTime LastLogon{
get { return lastLogon; }
set { lastLogon = value; }
}
}


Add the mapping file user.hbm.xml and set its build action as embedded resource

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="quickstart.User, quickstart" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>


add an app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property>
<property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
<property name="connection.connection_string">Server=(local);database=NHibernate;Integrated Security=SSPI;</property>
<property name="show_sql">false</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="use_proxy_validator">true</property>
</session-factory>
</hibernate-configuration>
</configuration>


download and extract nhibernate to a folder
set references from ur winapp to nhibernate.dll, LinFu.Dynamic.Proxy.dll, NHibernate.ByteCode.LinFu.dll

add some handler to ur app and paste this code

Configuration cfg = new Configuration();
cfg.AddAssembly("quickstart");
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;

// Tell NHibernate that this object should be saved
session.Save(newUser);

// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();

find the dbid by running
select * from master..sysdatabases
run profiler create new trace filter for the dbid of ur db (users)
step thru the above code
u should get a trace like this

exec sp_reset_connection
go
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;BEGIN TRANSACTION
go
exec sp_executesql N'INSERT INTO users (Name, Password, EmailAddress, LastLogon, LogonId) VALUES (@p0, @p1, @p2, @p3, @p4)', N'@p0 nvarchar(11),@p1 nvarchar(6),@p2 nvarchar(12),@p3 datetime,@p4 nvarchar(8)', @p0 = N'Joseph Cool', @p1 = N'abc123', @p2 = N'joe@cool.com', @p3 = 'Mar 3 2010 8:54:54:000AM', @p4 = N'joe_cool'
go
COMMIT TRANSACTION
go

if u check the db there should be a record for joe


if wan more info http://groups.google.com/group/nhusers
if wana copy/paste between local comp and remote desktop follow these steps
http://cutecomputer.wordpress.com/2007/01/03/howto-copy-paste-between-local-and-remote-desktop/

Thursday, December 24, 2009

Some bugs

This is how the partitions of my hard drive look in Vista. I have like five primary partitions and an extended one that holds nothing


Now this is for those pure souls who, despite living in our cruel globalized world, love and support their own alphabet. I am receiving here a response from a nice company that I buy computer components from. I wrote them using Latin and even though it may be ugly they understood my letter. I received a response in Cyrillic and the answer is probably very professional, but who knows?!


This is how to handle the unlikely situation of your site going down
debian forums WILL RETURN

And here is another not-so-elegant-but-still-respectful solution of this situation


And here is how the pirates do it

Wednesday, February 11, 2009

UK had not seen that much snow (2 inches to be precise) for 15 years.



From gatwick


So all airports, buses, and trains in Southern England were closed and cancelled, and I had to test how comfortable the airport hallway floors are.

From gatwick


From gatwick


After discovering that sleeping on the floor of an English airport is not a fun adventure, I took the advise of a fellow Bulgarian whom I met at the airport, that the only way home goes through Greece.

Athens greeted me with a 5 pm temperature of 17 degrees and clear and sunny skies.
I stayed in Greece for the night and the next day I took some pictures.

From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


From athens


Parliament of Greece







The Bank of Greece



Theatre [I think] of Greece



Then I took the bus to Bulgaria, where all the following pictures are from [bear in mind I took them while on bus hence they could be a bit blurry].