SSH.net之model層

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   sp   for   on   

建立一個項目,第一個net版本的ssh項目,命名為:Nssh.project:建立類庫,作為項目model層然後,開始編寫代碼: 
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Model{    public class Users    {        public virtual int userID { get; set; }        public virtual string uname { get; set; }        public virtual Roles roles { get; set; }//一個使用者有一個角色,一個角色可以有多個使用者    }}

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Model{    public class Roles    {        public virtual int rolesID { get; set; }        public virtual string RolesName { get; set; }                public virtual IList<Users> UserList { get; set; }//一個使用者有一個角色,一個角色可以有多個使用者        public virtual IList<Permission> permissionList { get; set; }//使用者角色與許可權是多對多關係    }}

 

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Model{    public class Permission    {        public virtual int permissionID { get; set; }        public virtual string PermissionName { get; set; }        public virtual IList<Roles> rolesList { get; set; }//使用者角色與許可權是多對多關係    }}

 

 

hbm.xml檔案

<?xml version="1.0" encoding="utf-8" ?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">    <class name="Model.Users, Model" table="P_Users">        <id name="userID" column="userID" type="int" >            <generator class="native" />        </id>        <property name="uname" column="uname" type="string" length="50" not-null="true"/>        <many-to-one name="roles" column="RoleID" />    </class></hibernate-mapping>

 

<?xml version="1.0" encoding="utf-8" ?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">    <class name="Model.Roles, Model" table="P_Roles">        <id name="rolesID" column="rolesID" type="int" >            <generator class="native" />        </id>        <property name="RolesName" column="RolesName" type="string" length="50" not-null="true"/>                <!--Bag:對象集合,每個元素可以重複。例如{1,2,2,6,0,0},在.Net中相當於IList或者IList<T>            實現。            Set:對象集合,每個元素必須唯一。例如{1,2,5,6},在.Net中相當於ISet或者ISet<T>                實現,Iesi.Collections.dll程式集提供ISet集合。            List:整數索引對象集合,每個元素可以重複。例如{{1,"YJingLee"},{2,"CnBlogs"},{3,"LiYongJing"}},在.Net中相當於ArraryList或者List<T>                實現。            Map:索引值對集合。例如{{"YJingLee",5},{"CnBlogs",7},{"LiYongJing",6}},在.Net中相當於HashTable或者IDictionary<Tkey,TValue>                實現。        -->        <bag name="UserList" inverse="true" cascade="all-delete-orphan" table="P_Users">            <key column="rolesID" foreign-key="FK_user_role"/>            <one-to-many class="Model.Users, Model" />        </bag>        <bag name="permissionList" table="P_Role_Permission">            <key column="rolesID" foreign-key="FK_role_permission"/>            <many-to-many class="Permission" column="permissionID"/>        </bag>    </class></hibernate-mapping>

 

<?xml version="1.0" encoding="utf-8" ?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model">    <class name="Model.Permission, Model" table="P_Permission">        <id name="permissionID" column="permissionID" type="int" >            <generator class="native" />        </id>        <property name="RolesName" column="RolesName" type="string" length="50" not-null="true"/>                <bag name="rolesList" table="P_Role_Permission">            <key column="permissionID" foreign-key="FK_role_permission"/>            <many-to-many class="Roles" column="rolesID"/>        </bag>    </class></hibernate-mapping>

 

最後記得設定hbm.xml檔案屬性:

SSH.net之model層

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.