zoukankan      html  css  js  c++  java
  • .Net 一对一的双向关联Map写法

           systemuser  与 systemuserlogin  为1对1的关联关系:

           systemuserMap:  HasOne<SystemUserLogin>(o => o.SystemUserLogin).Cascade.All().PropertyRef("SystemUser"); 

           systemuserloginMap:References<SystemUser>(o => o.SystemUser).Column("SystemUserID").Unique(); //.Unique()对“SystemUserID”进行了唯一性限定

           注意:此处Map文件中生成的1对1 的关联关系当其存储到数据库中时,才会产生。

          例子:

      [Test]
            public void Test_user_loginuser_findeach() 
            {
    
    
                IRepository<SystemUser> repos = UnityHelper.UnityToT<IRepository<SystemUser>>();
                SystemUser s = new SystemUser()
                {
                    Name = "findpangfuxing",
                    Email = "findpang@126.com",
                    Description = "findtest"
                };
                repos.SaveOrUpdate(s);
    
                IRepository<SystemUserLogin> reposl = UnityHelper.UnityToT<IRepository<SystemUserLogin>>();
                SystemUserLogin sl = new SystemUserLogin()
                {
                    LoginName = "findpfx",
                    Password = "findpang@126.com",
                    SystemUser = s
                };
                reposl.SaveOrUpdate(sl);
    
                SystemUserLogin suff = new SystemUserLogin();
                //测试1:
                suff = s.SystemUserLogin;       //运行至此处,发现  s.SystemUserLogin=null
                suff = repos.Load(s.Id).SystemUserLogin;  //运行至此处,发现  s.SystemUserLogin=null
                //原因是,此处在运行时,检测到内存中s对象已存在,故直接从内存数据中读取s对象,未从数据库中读取
    
                //测试2:
                suff = repos.Load("b756ab67-893c-4391-8a9b-b912b64dedda").SystemUserLogin;  //发现可以取到 s.SystemUserLogin
                //原因是,从数据库中读取的对象
                string a = suff.LoginName;
            }
  • 相关阅读:
    题解 P4999 【烦人的数学作业】
    题解 P2657 【[SCOI2009] windy 数】
    题解【洛谷 P1466 [USACO2.2]集合 Subset Sums】
    乘法逆元
    浅谈二维前缀和
    浅谈位运算
    浅谈 Lucas 定理
    浅谈 exgcd
    【洛谷P1754 球迷购票问题】题解
    RPA机器人工厂化时代下,艺赛旗要做什么样的“四新”产品
  • 原文地址:https://www.cnblogs.com/wukong0214/p/2879501.html
Copyright © 2011-2022 走看看