I have a view that I am going to only read from (no writes). This view does not have any unique key (not event composite).
So how can I map this view in NHibernate without touching the view? I do not want to add a new column to the view to generate a unique identity for me. Is there a way to map this view and generate the identity column on the NHibernate side?
I can generate a GUID in my entity class like:
public class MyViewClass
{
private Guid _id = new Guid();
public virtual Guid Id { get { return _id; } set { _id = value; } }
}
But how can I make the mapping work? The following code does not work:
public class MyViewClass: ClassMapping<MyViewClass>
{
public MyViewClass()
{
Mutable(false);
Id(x => x.Id, m => m.Generator(Generators.Guid));
}
}
It expects to have the Id column in view and throws:
System.Data.SqlClient.SqlException: Invalid column name 'Id'.
BTW, I am using NHibernate 3.2 and mapping by code.