Question

I am using Poco Generator with entity framework, And Poco Proxy class have been generated successfully,

For a single table all the things goes fine,

herein I've listed the main part of my classes and explain relations between tables. There are 3 table that they have many-to-many relation as follows:

1- Authority 2- Ability 3- AuthorityAbilityMap

Each Authority can have many Ability and vice verse. The main problem is that Navigation property in Authority Class doesn't work.

The Authority class is (just a part of class listed):

 public partial class Authority 
{
    .
    .
    .
    public virtual ICollection<AuthorityAbilityMap> AuthorityAbilityMaps
    {
        //Poco implementation 
    }
    private ICollection<AuthorityAbilityMap> _authorityAbilityMaps;
    .
    .
    .
}

And Ability class:

 public partial class Ability : IAuditable
{
   .
   .
   .      
    public virtual ICollection<AuthorityAbilityMap> AuthorityAbilityMaps
    {
        //Poco implementation contains get and set.
    }
    private ICollection<AuthorityAbilityMap> _authorityAbilityMaps;
}

And AuthorityAbilityMaps navigation properties:

 public virtual Ability Ability
    {
        get { return _ability; }
        set
        {
            if (!ReferenceEquals(_ability, value))
            {
                var previousValue = _ability;
                _ability = value;
                FixupAbility(previousValue);
            }
        }
    }
    private Ability _ability;
    public virtual Authority Authority
    {
        get { return _authority; }
        set
        {
            if (!ReferenceEquals(_authority, value))
            {
                var previousValue = _authority;
                _authority = value;
                FixupAuthority(previousValue);
            }
        }
    }

The source code tested against above classes is as following :

AuthorityEntities authorityContext = new AuthorityEntities();
                Authority authority = authorityContext.Authorities.Where(x => x.AID == 85).FirstOrDefault();
                ICollection<AuthorityAbilityMap> allMaped = authority.AuthorityAbilityMaps;

allMaped contains 0 member.

As you know the navigation properties will created by Poco Generator,

In fact I want to use these Navigation properties to load all relation-ed records and supply multiple Ability in bulk for a specific Authority.

Thanks in advance.

Was it helpful?

Solution

I defined Authority's primary key and Ability's primary key as primary keys for AuthorityAbilityMap and it works well, they have been used as foreign keys in AuthorityAbilityMap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top