Am I doing something with Nhibernate Query Over fetch?

I have it

   using (ITransaction transaction = session.BeginTransaction())
        {
            Task tAlias = null;
            CompletedTask cAlias = null;

            List<Task> tasks = session.QueryOver<Task>(() => tAlias)
                .Where(Restrictions.In(Projections.Property(() => tAlias.Course.Id), courseIds))
                .Fetch(pt => pt.PersonalTaskReminders).Eager
                .List<Task>().ToList().ConvertToLocalTime(student);


            transaction.Commit();

            return tasks;
        }

    PersonalTaskReminders == Collection

Thus, a task can have many personal TaskReminders. I find that if I installed 2 personal dictionaries (so that PersonalTaskReminders will now have 2 lines in the collection from db)

So that he returns the same task twice.

So, if I had 50 personal fixes for this task. I would get 50 results of the same task. I do not understand why.

If I remove the download with impatience. I am returning one task from the database as I expected.

+3
source share
2 answers

, . , DistinctRootEntityTransformer.

, NHibernate IN. :

    var tasks = Session.QueryOver<Task>()
            .WhereRestrictionOn(x => x.Id).IsIn(courseIds)
            .Fetch(pt => pt.PersonalTaskReminders).Eager
            .TransformUsing(Transformers.DistinctRootEntity)
            .List<Task>();
+17

Xelibrion .

, Fetch, SQL:

Fetch SELECT Task.

Fetch SELECT PersonalReminder. , PersonalReminder Task, , DISTINCT ( , PersonalReminder),.

SQL, TransformUsing, , NH .

+1

All Articles