首页 > Web开发 > 详细

[Troubleshooting] Nhibernate usage

时间:2015-06-23 15:44:06      阅读:287      评论:0      收藏:0      [点我收藏+]

Id(x => x.Id).

1. NHibernate.PropertyValueException: not-null property references a nullor transient value ABC.DE.FG

Insert value does not set null

2. Row was updated or deleted by another transaction (orunsaved-value mapping was incorrect)

try
{
	Session.Persist(instance);
}
catch (PersistentObjectException e)
{
	try
	{
		Session.Merge(instance);
	}
	catch (StaleObjectStateException ex)
	{
		Session.Save(instance);
	}
}

3. NHibernate: SqlDateTime overflow. Must be between 1/1/175312:00:00 AM and 12/31/9999 11:59:59 PM.

Reason: System.DateTime is avalue type in .Net, which means that it can never be null. But what happenswhen you have a nullable date time in the database, and you load it into aDateTime type? When NHibernate loads a null value from the database, itcannot put a null in the UpdatedDate property, the CLR doesn‘t allow it. Whathappens is that the UpdatedDate property is set to the default DateTime value,in this case: 01/01/0001.

Solution:

public virtual DateTime UTCCreateDt { get; set; }

->public virtual DateTime? UTCCreateDt { get; set; }

->public virtual Nullable<DateTime> UTCCreateDt {get; set; }

4.  FluentNHibernate.Cfg.FluentConfigurationException:An invalid or incomplete configuration was used while creating aSessionFactory. Check PotentialReasons collection, and InnerException for moredetail.

---> FluentNHibernate.Visitors.ValidationException: Theentity ‘AccrualMethodModel‘ doesn‘t have anId mapped. Use the Id method to map your identity property. Forexample: 

Reason: Every mapping requires an Id of some kind. The Id ismapped using the Id method, which takes a lambda expression thataccesses the property on your entity that will be used for the Id. Depending onthe return type of the property accessed in the lambda, Fluent NHibernate willmake some assumptions about the kind of identifier you‘re using. For example,if your Id property is an int, an identity column is assumed. Similarly,if you use a Guid then a Guid Comb isassumed.

Id(x => x.Id);

Note that the property you supply to Id can haveany name; it does not have to be called "Id," as shown here.

[Troubleshooting] Nhibernate usage

原文:http://blog.csdn.net/wzhiu/article/details/46605063

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!