nhibernate - Mapping object id as int idententity -
i have domain objects in fluentnhibernate have id's of type object
int
(reasoning further below). right have sqlite end. want map id auto-increment. far have:
public class usermap : classmap<user> { public usermap() { table("users"); id(x => x.id).customtype<int>().generatedby.native(); map(x => x.email); } } public class user { public virtual object id { get; set; } public virtual string email { get; set; } }
but when maps being loaded throws fluentconfigurationexception
message identity type must integral (int, long, uint, ulong)
user.id
property (stack trace says happens when call native
. again, want auto-increment integer.
reasoning object id
we have business requirement support several rdbms's mongodb. aware bad idea, please focus on question. mongo uses objectid (a guid-like consecutive value type) it's default id type. idea hide actual id type (because it's data-layer dependent), reuse models , have 2 different data access implementations (mongo & nhibernate).
i ended fixing problem doing
id(x => x.id).customtype<int>() .generatedby.custom<global::nhibernate.id.identitygenerator>() .unsavedvalue(null);
for reason, fluent nhibernate doesn't understand .customtype<int>()
means int. had add custom generator bypass fluent's logic.
this fixes immediate problem, still need figure out how collections & foreign keys need work.
Comments
Post a Comment