源码如下
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;namespace ReadingRoom.Entity
{
#region ResourceCategory /// <summary>
/// NHibernate 的对象 ResourceCategory 映射到表 'Resource_Category'.
/// </summary>
public class ResourceCategory
{
#region 成员变量
protected string _id;
protected int _rcSortID;
protected string _rcName;
protected string _rcIcon;
protected int _rcCount;
protected string _rcMemo;
protected ResourceCategory _rcParent;
protected IList _rcParentResourceCategories; #endregion #region 构造函数 public ResourceCategory() { } public ResourceCategory(int rcSortID, string rcName, string rcIcon, int rcCount, string rcMemo, ResourceCategory rcParent)
{
this._rcSortID = rcSortID;
this._rcName = rcName;
this._rcIcon = rcIcon;
this._rcCount = rcCount;
this._rcMemo = rcMemo;
this._rcParent = rcParent;
} #endregion #region 公共属性 /// <summary>
/// 分类标识_rcID
/// </summary>
public virtual string Id
{
get {return _id;}
set
{
if ( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("赋给 Id 的是无效值", value, value.ToString());
_id = value;
}
} /// <summary>
/// 序号_rcSortID
/// </summary>
public virtual int RcSortID
{
get { return _rcSortID; }
set { _rcSortID = value; }
} /// <summary>
/// 分类名_rcName
/// </summary>
public virtual string RcName
{
get { return _rcName; }
set
{
if ( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("赋给 RcName 的是无效值", value, value.ToString());
_rcName = value;
}
} /// <summary>
/// 图标_rcIcon
/// </summary>
public virtual string RcIcon
{
get { return _rcIcon; }
set
{
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("赋给 RcIcon 的是无效值", value, value.ToString());
_rcIcon = value;
}
} /// <summary>
/// 资源数_rcCount
/// </summary>
public virtual int RcCount
{
get { return _rcCount; }
set { _rcCount = value; }
} /// <summary>
/// 备注_rcMemo
/// </summary>
public virtual string RcMemo
{
get { return _rcMemo; }
set
{
if ( value != null && value.Length > 1000)
throw new ArgumentOutOfRangeException("赋给 RcMemo 的是无效值", value, value.ToString());
_rcMemo = value;
}
}
/// <summary>
///
/// </summary>
public virtual ResourceCategory rcParent
{
get { return _rcParent; }
set { _rcParent = value; }
} /// <summary>
///
/// </summary>
public virtual IList rcParentResource_Categories
{
get { return _rcParentResourceCategories; }
set { _rcParentResourceCategories = value; }
} #endregion
} #endregion
}
配置文件如下 <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ReadingRoom.Entity.ResourceCategory, ReadingRoom.Entity" table="Resource_Category">
<id name="Id" type="String" unsaved-value="null">
<column name="rcID" length="50" sql-type="varchar" not-null="true" unique="true" index="PK_RESOURCE_CATEGORY"/>
<generator class="native" />
</id>
<property name="RcSortID" type="Int32">
<column name="rcSortID" length="4" sql-type="int" not-null="false"/>
</property>
<property name="RcName" type="String">
<column name="rcName" length="50" sql-type="nvarchar" not-null="false"/>
</property>
<property name="RcIcon" type="String">
<column name="rcIcon" length="255" sql-type="varchar" not-null="false"/>
</property>
<property name="RcCount" type="Int32">
<column name="rcCount" length="4" sql-type="int" not-null="false"/>
</property>
<property name="RcMemo" type="String">
<column name="rcMemo" length="1000" sql-type="nvarchar" not-null="false"/>
</property>
<many-to-one name="rcParent" class="ReadingRoom.Entity.ResourceCategory, ReadingRoom.Entity">
<column name="rcParentID" length="50" sql-type="varchar" not-null="false"/>
</many-to-one>
</class>
</hibernate-mapping>
添加的时候总是报错,说rcID不能为空,我是菜鸟,求高手指点~
ResourceCategory rcEntity = new ResourceCategory();
rcEntity.Id = System.Guid.NewGuid().ToString();
rcEntity.RcName = Validation.SQLFilter(txtName.Text.Trim());
rcEntity.RcMemo = Validation.SQLFilter(txtMemo.Text.Trim());
rcEntity.RcSortID = TypeParse.StrToInt(txtSortID.Text.Trim(), 0);
if (ResourceManager.CreateCategory(rcEntity))
{
JsHelper.AlertAndRedirect("添加成功", "addcategory.aspx?id=" + rcID, this.Page);
}
else
{
JsHelper.Alert("添加失败", this.Page);
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;namespace ReadingRoom.Entity
{
#region ResourceCategory /// <summary>
/// NHibernate 的对象 ResourceCategory 映射到表 'Resource_Category'.
/// </summary>
public class ResourceCategory
{
#region 成员变量
protected string _id;
protected int _rcSortID;
protected string _rcName;
protected string _rcIcon;
protected int _rcCount;
protected string _rcMemo;
protected ResourceCategory _rcParent;
protected IList _rcParentResourceCategories; #endregion #region 构造函数 public ResourceCategory() { } public ResourceCategory(int rcSortID, string rcName, string rcIcon, int rcCount, string rcMemo, ResourceCategory rcParent)
{
this._rcSortID = rcSortID;
this._rcName = rcName;
this._rcIcon = rcIcon;
this._rcCount = rcCount;
this._rcMemo = rcMemo;
this._rcParent = rcParent;
} #endregion #region 公共属性 /// <summary>
/// 分类标识_rcID
/// </summary>
public virtual string Id
{
get {return _id;}
set
{
if ( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("赋给 Id 的是无效值", value, value.ToString());
_id = value;
}
} /// <summary>
/// 序号_rcSortID
/// </summary>
public virtual int RcSortID
{
get { return _rcSortID; }
set { _rcSortID = value; }
} /// <summary>
/// 分类名_rcName
/// </summary>
public virtual string RcName
{
get { return _rcName; }
set
{
if ( value != null && value.Length > 50)
throw new ArgumentOutOfRangeException("赋给 RcName 的是无效值", value, value.ToString());
_rcName = value;
}
} /// <summary>
/// 图标_rcIcon
/// </summary>
public virtual string RcIcon
{
get { return _rcIcon; }
set
{
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("赋给 RcIcon 的是无效值", value, value.ToString());
_rcIcon = value;
}
} /// <summary>
/// 资源数_rcCount
/// </summary>
public virtual int RcCount
{
get { return _rcCount; }
set { _rcCount = value; }
} /// <summary>
/// 备注_rcMemo
/// </summary>
public virtual string RcMemo
{
get { return _rcMemo; }
set
{
if ( value != null && value.Length > 1000)
throw new ArgumentOutOfRangeException("赋给 RcMemo 的是无效值", value, value.ToString());
_rcMemo = value;
}
}
/// <summary>
///
/// </summary>
public virtual ResourceCategory rcParent
{
get { return _rcParent; }
set { _rcParent = value; }
} /// <summary>
///
/// </summary>
public virtual IList rcParentResource_Categories
{
get { return _rcParentResourceCategories; }
set { _rcParentResourceCategories = value; }
} #endregion
} #endregion
}
配置文件如下 <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ReadingRoom.Entity.ResourceCategory, ReadingRoom.Entity" table="Resource_Category">
<id name="Id" type="String" unsaved-value="null">
<column name="rcID" length="50" sql-type="varchar" not-null="true" unique="true" index="PK_RESOURCE_CATEGORY"/>
<generator class="native" />
</id>
<property name="RcSortID" type="Int32">
<column name="rcSortID" length="4" sql-type="int" not-null="false"/>
</property>
<property name="RcName" type="String">
<column name="rcName" length="50" sql-type="nvarchar" not-null="false"/>
</property>
<property name="RcIcon" type="String">
<column name="rcIcon" length="255" sql-type="varchar" not-null="false"/>
</property>
<property name="RcCount" type="Int32">
<column name="rcCount" length="4" sql-type="int" not-null="false"/>
</property>
<property name="RcMemo" type="String">
<column name="rcMemo" length="1000" sql-type="nvarchar" not-null="false"/>
</property>
<many-to-one name="rcParent" class="ReadingRoom.Entity.ResourceCategory, ReadingRoom.Entity">
<column name="rcParentID" length="50" sql-type="varchar" not-null="false"/>
</many-to-one>
</class>
</hibernate-mapping>
添加的时候总是报错,说rcID不能为空,我是菜鸟,求高手指点~
ResourceCategory rcEntity = new ResourceCategory();
rcEntity.Id = System.Guid.NewGuid().ToString();
rcEntity.RcName = Validation.SQLFilter(txtName.Text.Trim());
rcEntity.RcMemo = Validation.SQLFilter(txtMemo.Text.Trim());
rcEntity.RcSortID = TypeParse.StrToInt(txtSortID.Text.Trim(), 0);
if (ResourceManager.CreateCategory(rcEntity))
{
JsHelper.AlertAndRedirect("添加成功", "addcategory.aspx?id=" + rcID, this.Page);
}
else
{
JsHelper.Alert("添加失败", this.Page);
}
解决方案 »
- 关于母版页的一个问题
- asp.net里用滤镜的问题
- 超出顶级目录怎么解决
- System.Net.WebRequest.Create(Url);防火墙要开设哪些端口?
- 等于白给你们分 寻找控件
- 刚从事。NET工作,遇到这样的问题,求助好多人,都爱莫能助,希望在这能得到答案!
- 急!在线等!点击分页页码后,分页无法正常工作。解决马上给分。
- 当一个page Postback 时, 服务器会重新打开始页,但是我想当打开页时,垂直scrollbar 拉到ie 的底部,不知道行不行的?
- gridview里鼠标放上去,有提示,且提示是以表格显示的,显示内容也数据库里的字段
- 如何访问模板中的控件
- 求一存储过程,不复杂,只是步骤较多?????
- jquery问题,急,在线等。。。
现在想添加一条数据,使rcParentID为空,也就是添加根级分类,这是就报错rcID不能为空