C #. net uses nhib1_1.0 XML ing to record the whole process of errors

Source: Internet
Author: User
Tags stack trace
If you want to reprint it, Please retain your copyright: /*
* Description: C #. net uses the Nhibernate 1.0 XML ing to record the whole process of error-prone places during usage
* Auther: the sky is blue _ chongchong
* MSN: chongchong2008@msn.com
* Dates: 2005-12-14
* Copyright: chongchong2008 Yichang Hubei China
*/

 

1. The data type in the HBM. xml ing file of the bit type in the database can be int32 or Boolean. The data type in the HBM. xml ing file of the bit type in the database can be int32.
Do not write it as an int. It is wrong.
It can also be Boolean OR Boolean, but do not write it as bool. Otherwise, an error will occur !! 2. The types in the object data definition must be consistent with those defined in the XML ing file. Public String IP // read-only attribute
{
GET/* Note that the writable attribute is commented out, and an error will be reported when this data is bound */
{
This. IP = httpcontext. Current. Request. servervariables ["remote_addr"]. tostring ();
Return this. IP;
}
} After determining the type, the type in the object data definition must be consistent with the type defined in the XML ing file, The definitions below are inconsistent. XML ing File
<Property name = "ispass" type = "Boolean" length = "1"/> Data entity file
Public int ispass
{
Get {return this. ispass ;}
Set {This. ispass = value ;}
} If you write a picture as above, the following error is reported: Server Error in '/mynh' application.
--------------------------------------------------------------------------------
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current Web request. please review the stack trace for more information about the error and where it originated in the code. exception details: system. invalidcastexception: specified cast is not valid. source error: Line 68: Try
Line 69 :{
Line 70: Session. Save (userentity); // Save the data entity
Line 71: Session. Flush ();
Line 72: transaction. Commit (); // The correct transaction submission should be written as follows: XML ing File
<Property name = "ispass" type = "Boolean" length = "1"/> data entity file
Public bool ispass
{
Get {return this. ispass ;}
Set {This. ispass = value ;}
}

3. You should bind the read/write attributes to the server control. When binding the ilist object returned by NH to server controls such as DataGrid, note that if you have to use an attribute
For example, it is an IP address. Although this attribute can be fully defined as read-only, if you need to bind this attribute to a column of a server control such as DataGrid,
So please pay special attention to it. You need to define this read-only attribute as a readable attribute, although it does not make sense to define it as Writable,
However, NH needs to write attributes to help set the correct data,
Otherwise, the following error is reported:

As follows: Code , The DataGrid uses (bound) The Public String IP property of the IP address // read-only property
{
Get
{
This. IP = httpcontext. Current. Request. servervariables ["remote_addr"]. tostring ();
Return this. IP;
}
} Server error in '/mynh' application.
-------------------------------------------------------------------------------- Property set method not found.
Description: An unhandled exception occurred during the execution of the current Web request. please review the stack trace for more information about the error and where it originated in the code. exception details: system. argumentexception: property set method not found. source error: Line 53: Using (isession session = nhelper. sessions (). opensession () // obtain the current session of the session Factory
Line 54 :{
Line 55: Return session. Find ("from chongchong. mynh. Business. userentity ");
Line 56 :}
Line 57 :}
Source File: D: \ chongchong \ chongchong_web \ mynh \ business \ businesslogic. CS line: 55 stack trace: the correct code should be like this: Public String IP
{
Get
{
This. IP = httpcontext. Current. Request. servervariables ["remote_addr"]. tostring ();
Return this. IP;
}

Set/* Note that the writable attribute is commented out, and an error will be reported when this data is bound */
{
This. IP = value;
}}

 

Note that if the returned ilist set is empty, bind the returned data to your control directly. An error is returned !!

 

 

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.