Using IRepository in Orchard

Topics: Customizing Orchard, Writing modules
Nov 29, 2011 at 3:18 PM

I have an (IRepository<TopicsRecord>  topicRepository)

 

 

With a LINQ to SQL query that is joining one other record in the query. I am returning _topicsRepository.T0List().

 

My question is do I need a second repository for the record I am joining? 

Nov 29, 2011 at 7:20 PM

Im getting a compile time error when using Isession session:

Compiler Error Message: CS0103: The name 'session' does not exist in the current context

Source Error:

 
Line 38:             
Line 39:          {
Line 40:       
Line 41:             _session = session;
Line 42:             _topicsRepository = topicsRepository;

Heres my Service class. Where am I going wrong?

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Linq;
using Orchard;
using Orchard.ContentManagement;
using Orchard.Data;
using Pryor.WebinarAudio.Models;
using Pryor.WebinarAudio.ViewModels;
using FluentNHibernate;

namespace Pryor.WebinarAudio.Services
{
    public interface IWebinarService : IDependency
    {
       

         void UpdateTopicsForContentItem(ContentItem item, WebinarAudioEditorViewModel model);

        IEnumerable<TopicsRecord> GetTopics();



    }

    public class WebinarService : IWebinarService
    {
        private readonly ISession _session;
     
         private readonly IRepository<TopicsRecord> _topicsRepository;

  

         public WebinarService(IRepository<TopicsRecord> topicsRepository, ISession session)
            
         {
      
            _session = session;
            _topicsRepository = topicsRepository;

           
         }

        public void UpdateTopicsForContentItem(ContentItem item, WebinarAudioEditorViewModel model)
        {
            

            var webinarAudioPart = item.As<WebinarAudioPart>();
                webinarAudioPart.Length = model.Length;
                webinarAudioPart.Date = model.Date;
                webinarAudioPart.Prditmmst.Description = model.Description;
                webinarAudioPart.Topic.BrochureDesc = model.BrochureDesc;
                webinarAudioPart.Topic.ControlPrice = model.ControlPrice;
                webinarAudioPart.Topic.City = model.City;
                webinarAudioPart.Topic.URL = model.URL;
                webinarAudioPart.Topic = _topicsRepository.Get(
                   s => s.TopicCode == model.TopicCode);
                  
            
        }

     

        public IEnumerable<TopicsRecord> GetTopics()
        {
          var query = _session.CreateSQLQuery(@"SELECT TopicCode
              ,BrochureDesc
              ,URL
              ,ControlPrice   
              ,City
              ,Pryor_WebinarAudio_PrdItmmstRecord.Description
          FROM Pryor_WebinarAudio_Topics
          Inner join Pryor_WebinarAudio_PrdItmmst on Pryor_WebinarAudio_Topics.TopicCode = Pryor_WebinarAudio_PrdItmmst.ItemNumber ");
        
     
            return _topicsRepository.Table.ToList();
            
        }


        
    }


}

 

Coordinator
Nov 29, 2011 at 8:28 PM

I don't know, but I doubt this is the code that it's trying to compile: line 40 is not there in the code you copied.

Nov 29, 2011 at 9:20 PM

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate;
using NHibernate.Linq;
using Orchard;
using Orchard.ContentManagement;
using Orchard.Data;
using Pryor.WebinarAudio.Models;
using Pryor.WebinarAudio.ViewModels;
using FluentNHibernate;

namespace Pryor.WebinarAudio.Services
{
    public interface IWebinarService : IDependency
    {
       

         void UpdateTopicsForContentItem(ContentItem item, WebinarAudioEditorViewModel model);

        IEnumerable<TopicsRecord> GetTopics();



    }

    public class WebinarService : IWebinarService
    {
        private readonly ISession _session;
     
         private readonly IRepository<TopicsRecord> _topicsRepository;

  

         public WebinarService(IRepository<TopicsRecord> topicsRepository, ISession session)
            
         {
      
            _session = session;				<<--- The Error Is referring to this line. It says "The name 'session' does not exist in the current context"  This is Line 40 in my Webmatrix
            _topicsRepository = topicsRepository;

           
         }

        public void UpdateTopicsForContentItem(ContentItem item, WebinarAudioEditorViewModel model)
        {
            

            var webinarAudioPart = item.As<WebinarAudioPart>();
                webinarAudioPart.Length = model.Length;
                webinarAudioPart.Date = model.Date;
                webinarAudioPart.Prditmmst.Description = model.Description;
                webinarAudioPart.Topic.BrochureDesc = model.BrochureDesc;
                webinarAudioPart.Topic.ControlPrice = model.ControlPrice;
                webinarAudioPart.Topic.City = model.City;
                webinarAudioPart.Topic.URL = model.URL;
                webinarAudioPart.Topic = _topicsRepository.Get(
                   s => s.TopicCode == model.TopicCode);
                  
            
        }

     

        public IEnumerable<TopicsRecord> GetTopics()
        {
          var query = _session.CreateSQLQuery(@"SELECT TopicCode
              ,BrochureDesc
              ,URL
              ,ControlPrice   
              ,City
              ,Pryor_WebinarAudio_PrdItmmstRecord.Description
          FROM Pryor_WebinarAudio_Topics
          Inner join Pryor_WebinarAudio_PrdItmmst on Pryor_WebinarAudio_Topics.TopicCode = Pryor_WebinarAudio_PrdItmmst.ItemNumber ");
        
     
            return _topicsRepository.Table.ToList();
            
        }


        
    }


}
Coordinator
Nov 29, 2011 at 9:22 PM

Right, and that's not line 41 as claimed. And there is no error there.

Nov 29, 2011 at 9:22 PM

I mean the line 40 directly above is empty but that's just white space. Obviously its referring to the line below. I don't know. Webmatrix Bug??

Coordinator
Nov 29, 2011 at 9:38 PM

Doesn't make any sense, session clearly exists. That's not an Orchard issue in any case, it's a C# compilation issue.