How to customize many-to-one relation

27 views
Skip to first unread message

Gmail

unread,
May 29, 2011, 2:19:00 AM5/29/11
to codeconform
Dears,
 
I've got the domains about the app-rights-Role relations:
1. A role has a Rights
2. a Rights has a Menu and a RightsCode , the RightsCode value is like 1111,1101 ,etc, it means if have the CRUD rights
 
and i have two problem:
1. I could not delete the Menu's record firstly.
2. The Rights's Id is not a native Id
 
-----domain code--------------------------------
   public class Role
    {
        public int Id { get; set; }
        public string RoleName { get; set; }        
        public IList<Rights> Rights { get; set; }
    }
    public class Rights
    {
        public int Id { get; set; }
        public Menu Menu { get; set; }
        public string RightsCode { get; set; }
    }
    public class Menu
    {
        public int Id { get; set; }
        public string MenuName { get; set; }
    }
----------- mapping code---------------------
 
            var orm = new ObjectRelationalMapper();
            orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
            
            IEnumerable<Type>  entities = new[] { typeof(Menu), typeof(Rights) };           
            orm.TablePerClass(entities);
            orm.ManyToOne<Rights, Menu>();
            Mapper mapper = new Mapper(orm);
           
            mapper.Class<Menu>(cm =>
            {
                cm.Table("Tb_Sys_Menu");
            });
            mapper.Class<Rights>(cm =>
            {
                cm.Table("Tb_Sys_Rights");
                cm.Id(u => u.Id, im => { im.Generator(Generators.Foreign<Rights>(u => u.Menu)); });
                cm.ManyToOne(person => person.Menu, mtom =>
                {
                    mtom.Unique(false);
                    mtom.NotNullable(true);
                    mtom.Cascade(Cascade.All);
                });
            });
-------------------------
 
 
It's very kind of you to help me!
 
2011-05-29

btlyeo
from China.Inner Mongolia Hohhot

Fabio Maulo

unread,
May 29, 2011, 7:08:26 PM5/29/11
to codec...@googlegroups.com
orm.OneToOne<Right, Menu>();
and remove all others stuff you put there.
--
Fabio Maulo

Fabio Maulo

unread,
May 29, 2011, 7:09:39 PM5/29/11
to codec...@googlegroups.com

Gmail

unread,
May 29, 2011, 8:44:51 PM5/29/11
to codeconform
I modify the code like this,and it is still have the wrong  deleting  the menu's record before deleting the Rights's record.
 
--------------------------------------------------
var orm = new ObjectRelationalMapper();
            orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
            IEnumerable<Type> entities = new[] { typeof(Menu), typeof(Rights) };
            orm.TablePerClass(entities);
            orm.OneToOne<Rights, Menu>();
             
            Mapper mapper = new Mapper(orm);
            mapper.Class<Rights>(cm =>
            {
                cm.Table("Tb_Sys_Rights");               
            });
            mapper.Class<Menu>(cm =>
            {
                cm.Table("Tb_Sys_Menu");
            })
 
2011-05-30

Gmail

发件人: Fabio Maulo
发送时间: 2011-05-30  07:09:42
收件人: codeconform
抄送:
主题: Re: [ConfORM] How to customize many-to-one relation

Fabio Maulo

unread,
May 30, 2011, 7:54:16 AM5/30/11
to codec...@googlegroups.com
but it is another problem related to NH usage/cascade.

--
Fabio Maulo 

Reply all
Reply to author
Forward
0 new messages