Hi,
okay, there is new information on this issue.
I figured out how it _should_ work when adding dynamic updates and
optimistic locking with a version field.
I use overrides on the Automappings to manage this. But when I add the
DateTime property called Version to the Version override, I get a
runtime error: "Error: Common Language Runtime detected an invalid
program."
When I extract the overrides into a seperate override class for my
business object, then I'll get an error also at the
Version mapping, where it states that System.DateTime cannot be used
as a return value for System.Object.
Now I'm really lost at this one.
First configuration version (Invalid Program):
class method DatabaseConfiguration.CreateSessionFactory:
ISessionFactory;
begin
exit Fluently.Configure()
.Database( getDB(DBType.MSSql) ) // a normal DB config
.Mappings(m ->
m.AutoMappings
.Add(
AutoMap.AssemblyOf<Customer>()
.IgnoreBase<NHibernateBusinessLogic.PersistenceBase.NHibernateBaseClass>
() // exclude the base class
.Where(t -> t.Namespace =
'NHibernateBusinessLogic.BusinessObjects') // my BO namespace
.Override<Customer>(map -> map.DynamicUpdate())
.Override<Customer>(map -> map.Version(x -> x.Version)) //
<-- this is the problematic line
))
.ExposeConfiguration(new Action<Configuration>(BuildSchema))
.BuildSessionFactory();
end;
class method DatabaseConfiguration.BuildSchema(config: Configuration);
begin
config.SetProperty('hbm2ddl.auto', 'create');
end;
Second one with external overrides:
m.AutoMappings
.Add(
AutoMap.AssemblyOf<Customer>()
.IgnoreBase<NHibernateBusinessLogic.PersistenceBase.NHibernateBaseClass>
()
.Where(t -> t.Namespace =
'NHibernateBusinessLogic.BusinessObjects')
.UseOverridesFromAssemblyOf<CustomerOverrides>()
))
where my CustomerOverrides looks like this:
CustomerOverrides = public class (IAutoMappingOverride<Customer>)
public
method &Override(mapping: AutoMapping<Customer>);
end;
implementation
method CustomerOverrides.&Override(mapping: AutoMapping<Customer>);
begin
mapping.DynamicUpdate();
mapping.Version(x -> x.Version); // System.DateTime cannot be used
for System.Object as a return value
end;
I have this base class:
NHibernateBaseClass = public abstract class
public
property Id: Integer read protected write; virtual;
property Version: DateTime read protected write; virtual;
end;
and some classes derived from that, like my Customer:
Customer = public class (NHibernateBaseClass)
public
property Name: String; virtual;
property Description: String; virtual;
property Projects: IList<Project> := new List<Project>; virtual;
property Users: IList<User> := new List<User>(); virtual;
end;
For test reasons you can leave out the lists of Projects and Users.
They're not important at all.
Regards,
Sebastian