[Troubleshooting] Nhibernate usage

Source: Internet
Author: User

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 the it can never be null. But what Happenswhen has a nullable date time in the database, and do 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 all ow it. Whathappens is, the Updateddate property was 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 is used while creating aSes Sionfactory. Check potentialreasons Collection, and innerexception for Moredetail.

---> FluentNHibernate.Visitors.ValidationException:Theentity ' accrualmethodmodel ' doesn ' t has anId Mapped. Use the Id of 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 would be Used for the Id. Depending onthe return type of the property accessed in the lambda, Fluent NHibernate willmake some assu Mptions about the kind of identifier you ' re using. For example,if your The Id property is a int, an identity column is assumed. Similarly,if you use a GUID and then a GUID comb isassumed.

Id(x => x.Id);

Note that the property, supply to Id can haveany name; It does not has the called "Id," as shown here.

[Troubleshooting] Nhibernate usage

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.