У меня есть тестовый метод, как показано ниже:
public void Add_Update_Delete_a_Registration() {
ISessionFactory sessionFactory = SessionFactory.GetSessionFactory(connString);
using (ISession session = sessionFactory.OpenSession()) {
Course course = new CourseRepository(session).GetById(12019);
Registration entity = new Registration();
entity.Course = course; //Assign the Course to register
//assign other entity members
//...
RegistrationRepository repository = new RegistrationRepository(session);
repository.Add(entity);
}
Правильно вставлен объект регистрации.
Проблема в том, что NHibernate также сделал вызов базы данных UPDATE, чтобы обновить объект курса, которыйне изменяется вообще в методе теста.Какие могут быть возможные причины?
Отображения:
public class CourseMap : ClassMap<Course>{
public CourseMap() {
Id(x => x.Id).GeneratedBy.HiLo("100");
Map(x => x.WeekDay)
.Not.Nullable()
.CustomType<int>(); //WeekDay is type of DayOfWeek enums
References(x => x.Room)
.Not.Nullable();
Map(x => x.StartTime)
.Not.Nullable();
Map(x => x.EndTime)
.Not.Nullable();
Map(x => x.CreatedTime)
.Not.Nullable();
Map(x => x.UpdatedTime);
Map(x => x.CreatedBy)
.Not.Nullable();
Map(x => x.UpdatedBy);
Version(x => x.Version).Column("RCB_Version")
.CustomSqlType("timestamp")
.Generated.Always()
.Not.Nullable();
}
public class RegistrationMap : ClassMap<Registration>{
public RegistrationMap() {
Id(x => x.Id)
.GeneratedBy.HiLo("100");
Map(x => x.OwnerWindowsAccount)
.Not.Nullable()
.Length(50);
References(x => x.Course)
.Not.Nullable();
Map(x => x.TrainingDate)
.Not.Nullable();
Map(x => x.RegistreeName)
.Not.Nullable()
.Length(50);
Map(x => x.RegistreeWindowsAccount)
.Nullable()
.Length(50);
Map(x => x.CreatedTime)
.Not.Nullable();
Map(x => x.UpdatedTime);
Map(x => x.CreatedBy)
.Not.Nullable();
Map(x => x.UpdatedBy);
Version(x => x.Version)
.CustomSqlType("timestamp")
.Generated.Always()
.Not.Nullable();
}
}
Очень ценится!Leo