码迷,mamicode.com
首页 > Web开发 > 详细

[Troubleshooting] Nhibernate usage

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

标签:nhibernate

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

标签:nhibernate

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!