private IQueryable <TLink> FindPolymorphicLinks <TLink, TRole, TOwner>(TRole value)
            where TRole : class
            where TLink : class, IPolymorphicLinkWithOid <TRole, TOwner>
            where TOwner : class, IHasIntegerId
        {
            string roleOid = ObjectFinder.GetCompoundKey(value);

            return(Container.Instances <TLink>().Where(x => x.RoleObjectOid == roleOid));
        }
        public virtual TLink NewTransientLink <TLink, TRole, TOwner>(TRole value, TOwner owner)
            where TRole : class
            where TLink : class, IPolymorphicLinkWithOid <TRole, TOwner>, new()
            where TOwner : class, IHasIntegerId
        {
            if (value == null)
            {
                return(null);
            }

            var link = Container.NewTransientInstance <TLink>();

            link.Owner         = owner;
            link.RoleObjectOid = ObjectFinder.GetCompoundKey(value);
            return(link);
        }
        public virtual TLink UpdateAddOrDeleteLink <TLink, TRole, TOwner>(TRole value, TLink link, TOwner owner)
            where TRole : class
            where TLink : class, IPolymorphicLinkWithOid <TRole, TOwner>, new()
            where TOwner : class, IHasIntegerId
        {
            if (link != null)
            {
                if (value == null)
                {
                    Container.DisposeInstance(link);
                    return(null);
                }

                link.RoleObjectOid = ObjectFinder.GetCompoundKey(value);
                return(link);
            }

            if (Container.IsPersistent(this) && value != null)
            {
                return(AddLink <TLink, TRole, TOwner>(value, owner));
            }

            return(null);
        }