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;
            }
  • 相关阅读:
    shell脚本比较字符串相等
    从自身的经历讨论手工测试与自动化测试
    读《Linux Shell脚本攻略》(第2版) 一遍、二遍体会
    也许开发需要的只是一份简单明了的表格
    linux 命令:tr 的简单使用
    docker的数据持久化
    docker基础操作
    centos7 docker镜像源设置
    DockerUI(图形化管理)
    Docker 常用命令
  • 原文地址:https://www.cnblogs.com/wukong0214/p/2879501.html
Copyright © 2011-2022 走看看