using the GUID type as the primary key in NHibernate and saving the entity


I am using NH as my data access layer, and as it seems it has problems with GUID type as primary key :

public partial class Member
        public virtual Guid UserId { get; set; }
        public virtual string UserName { get; set; }

 public MemberMapping()
            Id(x => x.UserId).GeneratedBy.GuidComb();
            Map(x => x.UserName).Length(20).Not.Nullable();

as it seems, even when I change UserId to the following mapping:

Id(x => x.UserId).GeneratedBy.Assgined();

and then initialze the UserId my self, the object of type member is not begin saved...

But when I use Int data type for UserId it is being saved properly.

I read wont save to database with guid as id- fluent-nhiberate question and used Save() method for saving the member entity with GUIdD as key, but it does not work!

Thanks for your consideration.

The page you link to in your follow-up comment is about creating and injecting the session. It does not mention "transaction" or "commit" at all. You should always use NHibernate transactions. Under default settings, committing the transaction will trigger the session to flush any changes to the database. This is a necessary step, since flushing is the only step where changes are guaranteed to be sent to the database.

More on flushing: