In last year there is a tendency to use technologies of strongly typed
querying such as LINQ and QueryOver, and it's cool.
But, unfortunately, these technologies do not support the
encapsulation of entity properties, in contrast to the classical HQL
and CriteriAPI(with theirs "magic string" nature). Here is an
example:

    public class SomeBusinessEntity : Entity<Guid>
    {
        private IList<ItemEntity> items = new List<ItemEntity>();
        private SecureEntity payload;

        protected SomeBusinessEntity()
        {
        }

        public SomeBusinessEntity(SecureEntity payload)
        {
            this.payload = payload;
        }

        //Mapped
        protected virtual SecureEntity InternalPayload
        {
            get { return payload; }
            set { payload = value; }
        }

        //Mapped
        protected virtual IList<ItemEntity> InternalItems
        {
            get { return items; }
            set { items = value; }
        }

        //Maybe read only collection, it's should possible to use this
collection in queries
        public virtual IEnumerable<ItemEntity> Items
        {
            get { return InternalItems; }
        }

        //It's should possible to use this facade-property in queries

        public virtual ISecureEntity Payload
        {
            get { return InternalPayload; }
        }
    }

    public class ItemEntity : Entity<Guid>
    {
    }

    public class SecureEntity : Entity<Guid>, ISecureEntity
    {
        #region ISecureEntity Members

        public virtual int Priority { get; set; }

        #endregion

        public virtual void SomeRealImportantMethod()
        {
        }
    }

    public interface ISecureEntity
    {
        int Priority { get; }
    }

Now, there is no way to use InternalPayload and InternalItems in
strongly typed queries (The exception is the replacement of access
modifier "protected" by "protected internal" and use the attribute
"InternalsVisibleTo", but this is not a complete solution, because it
requires modification of the original assembly when new assemblies
containing queries.)

It would have been perfect if NHibernate allowed to do something like
this in mapping:

<many-to-one name="InternalPayload" query-alias="Payload" .../>

<bag name="InternalItems" query-alias="Items" ...>
..
</bag>

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to