What is the best solution to move complex queries from controller into repository?
<p>during creating my app I threw <code>Model layer</code> and <code>Repository layer</code> to separate projects. Each form in my app is represented by its own <code>ViewModel class</code>. All <code>ViewModel classes</code> are stored in folder <code>ViewModels</code> in MyApplicationName.Web. During <code>GET request</code> for <code>MyDrafts form</code>, the following  function  is launched:</p>

<pre><code>public ActionResult MyDrafts()
        {
            MyDraftsVM dataVM = GetDataMyDrafts();
            return View(dataVM);
        }


        private MyDraftsVM GetDataMyDrafts()
        {        
            MyDraftsVM dataVM = new MyDraftsVM();

            using (var context = new PrincipalContext(ContextType.Domain))
            {
                List&lt;MyDraftsVM.MyDraftVM&gt; userInvoices = new List&lt;MyDraftsVM.MyDraftVM&gt;();
                userInvoices = _repoExhibitor.Context.Exhibitors
                                                .Join(_repoExhibitor.Context.Invoices.Where(x =&gt; x.CreatedBy == User.Identity.Name &amp;&amp; x.Status == (int)(ModelEnums.Invoice.Status.Przygotowanie)),
                                                e =&gt; e.Id,
                                                i =&gt; i.Id,
                                                (e, i) =&gt; new { e, i })
                                                .ToList()
                                                .Select(s =&gt; new MyDraftsVM.MyDraftVM(s.e, s.i, UserPrincipal.FindByIdentity(context, s.i.CreatedBy).DisplayName))
                                                .ToList();

                List&lt;MyDraftsVM.MyDraftVM&gt; userCorrespondence = new List&lt;MyDraftsVM.MyDraftVM&gt;();
                userCorrespondence = _repoExhibitor.Context.CorrespondenceSenders
                                                    .Join(_repoExhibitor.Context.Correspondences.Where(x =&gt; x.CreatedBy == User.Identity.Name &amp;&amp; x.Status == (int)(ModelEnums.Invoice.Status.Przygotowanie)),
                                                    sen =&gt; sen.Id,
                                                    c =&gt; c.Id,
                                                    (sen, c) =&gt; new { sen, c })
                                                    .ToList()
                                                    .Select(s =&gt; new MyDraftsVM.MyDraftVM(s.c, UserPrincipal.FindByIdentity(context, s.c.CreatedBy).DisplayName))                                                 
                                                    .ToList();                                                    

                dataVM.Documents.AddRange(userInvoices);
                dataVM.Documents.AddRange(userCorrespondence);
            }
            return dataVM;
        }
</code></pre>

<p>MyDraftsVM class looks like this:</p>

<pre><code>public class MyDraftsVM
    {
        public MyDraftsVM()
        {
            this.Documents = new List&lt;MyDraftVM&gt;();
            this.Layout = "~/Views/Shared/_LayoutBox.cshtml";
        }

        public List&lt;MyDraftVM&gt; Documents { get; set; }
        /// &lt;summary&gt;
        /// layout path
        /// &lt;/summary&gt;      
        public string Layout { get; set; }

        public class MyDraftVM
        {


            public MyDraftVM()
            {
                this.DocumentPartial = new DocumentMemebership();
                this.InvoicePartial = new InvoiceMembership();
                this.ExhibitorPartial = new ExhibitorMembership();
                this.CorrespondencePartial = new CorrespondenceMembership();
            }

            public MyDraftVM(Exhibitor e, Invoice i, string createdBy)
            {              
                InvoicePartial = Mapper.Map&lt;MyDraftsVM.MyDraftVM.InvoiceMembership&gt;(i);
                ExhibitorPartial = Mapper.Map&lt;MyDraftsVM.MyDraftVM.ExhibitorMembership&gt;(e);
                DocumentPartial = new MyDraftsVM.MyDraftVM.DocumentMemebership()
                {
                    DocumentType = "Invoice",
                    Number = i.InvoiceNumber,
                    IssuingDate = i.IssuingDate,
                    CreatedBy = createdBy
                };
            }

            public MyDraftVM(Correspondence c, string createdBy)
            {
                CorrespondencePartial = Mapper.Map&lt;MyDraftsVM.MyDraftVM.CorrespondenceMembership&gt;(c);
                DocumentPartial = new MyDraftsVM.MyDraftVM.DocumentMemebership()
                {
                    DocumentType = "Correspondence",
                    Number = c.Signature,
                    IssuingDate = c.IssuingDate,
                    CreatedBy = createdBy,
                };
            }

            public DocumentMemebership DocumentPartial { get; set; }
            public InvoiceMembership InvoicePartial { get; set; }
            public CorrespondenceMembership CorrespondencePartial { get; set; }
            public ExhibitorMembership ExhibitorPartial { get; set; }


            public class InvoiceMembership : InvoiceVM
            {
                public virtual int Id { get; set; }
            }


            public class CorrespondenceMembership : CorrespondenceVM
            {

            }


            public class ExhibitorMembership : ExhibitorVM
            {
            }


            public class DocumentMemebership : DocumentVM
            {
            }


        }

    }
</code></pre>

<p>I’d like to move complex queries with <code>joins</code> to <code>repository</code> and here appears the problem. I would call this problem “problem of the interaction projects” because project <code>MyApplicationName</code> .Web has reference <code>MyApplicationName.Repository</code>. If I would like to move queries to <code>MyApplicationName.Repository</code>, I have to move there also <code>MyDraftsVM object</code>, which belongs to <code>MyApplicationName.Web</code>. 
The only solution which I see now, is to separate <code>ViewModels</code> folder as a separate project and the give a reference <code>MyApplicationName.Web</code> and <code>MyApplicationName.Repository</code> to this project. I don’t know if this is a good idea so that’s why I’m asking you.
If it’s not a good idea, can you give me better solution to move those complex queries to <code>repository</code>? Thank you.</p>