TrackInfo does not contain a definition for title (are you missing a using directive or an assembly)

26 views
Skip to first unread message

Mansuri Shahrukh

unread,
Jun 12, 2016, 6:22:13 AM6/12/16
to SolrNet

I am using below code for indexing a data from sql database but its give an error "mainWindow.TrackInfo' does not contain a definition for 'title' and no extension method 'title' accepting a first argument of type 'WpfApplication49.MainWindow.TrackInfo' could be found (are you missing a using directive or an assembly reference?)"  there are many solr field  i have added in it but in all field its give similar error. 


code is 


using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data.Sql;
using Microsoft.Practices.ServiceLocation;
using System.Data;
using SolrNet;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Xml.Serialization;
using Microsoft.Practices.ServiceLocation;
using SolrNet;
using SolrNet.Commands.Parameters;
using SolrNet.Exceptions;
using SolrNet.Impl;
using SolrNet.Commands.Parameters;
using SolrNet.Attributes;

namespace WpfApplication49
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        
        public class TrackInfo {
            
            [SolrField("title")]
            public string Name { get; set; }

            [SolrField("Author")]
            public IDictionary<string, object> OtherFields { get; set; }
                               }

        public string UploadToSolr()
        {
            int intCount = 0;

            ISolrOperations<TrackInfo> solr = ServiceLocator.Current.GetInstance<ISolrOperations<TrackInfo>>(); solr.Delete(SolrQuery.All);
            // Instanciate the metadata object 
            

            // Loop through the SQL Server Database then add a solr record 

            // Create a connection object and data adapter 

            string connetionString = null;
            SqlConnection connection;
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand cmd;
            string sql = null;
            SqlDataReader dataReader;
            connetionString = "Data Source=SHAHRUKH_PC/SQLEXPRESS;Initial Catalog=souldb;User ID=sa;Password=s";
            sql = "select  b.FValue as title,  E.FValue as Author, l.p852 as AccessionNo, l.a852 as location,l.k852 as ClassNo,l.status, w.fvalue as MeetingName , k.FValue as subtitle,u.FValue as Yearofpublication, c.FValue as ISBN, d.FValue as issn, k.FValue as subtitle,  f.FValue as roleofauthor, g.FValue as editor,  i.FValue as publisherPlace, h.FValue as publisher, x.FValue AS Series,  j.FValue as pyhsicaldescription, o.FValue as corporatename,v.FValue as Uniformtitle ,l.DateofAcq as AccessionDate, m.FValue as Note , l.Budget as Budget,  l.m852 as bookNo ,l.Price as Price,l.t852 as CopyNo,l.Supplier  as supplier ,l.b852 as collectionttype, l.Material As materials from Biblidetails b left join Biblidetails c on  b.RecID = c.RecID and c.Tag = 020 and c.SbFld = 'a'left join Biblidetails d on  b.RecID = d.RecID and d.tag = 022 and d.SbFld = 'a'left join Biblidetails w on  b.RecID = w.RecID and w.tag = 111 and w.SbFld = 'a'left join Biblidetails e on  b.RecID = e.RecID and e.Tag = 100 and e.SbFld = 'a'left join Biblidetails f on  b.RecID = f.RecID and f.Tag = 100 and f.SbFld = 'e' left join Biblidetails g on  b.RecID = g.RecID and g.Tag = 250 and g.SbFld = 'a'left join Biblidetails h on  b.RecID = h.RecID and h.Tag = 260 and h.SbFld = 'b'left join Biblidetails i on  b.RecID = i.RecID and i.Tag = 260 and i.SbFld = 'a'left join Biblidetails u on  b.RecID = u.RecID and u.Tag = 260 and u.SbFld = 'c'left join Biblidetails j on  b.RecID = j.RecID and j.Tag = 300 and j.SbFld = 'a' left join Biblidetails k on  b.RecID = k.RecID and k.Tag = 245 and k.SbFld = 'b' left join Biblidetails m on  b.RecID = m.RecID and m.Tag = 500 and m.SbFld = 'a' left join Biblidetails o on  b.RecID = o.RecID and o.Tag = 110 and o.SbFld = 'a'left join Biblidetails x on  b.RecID = x.RecID and x.Tag = 440 and x.SbFld = 'a'left join Biblidetails v on  b.RecID = v.RecID and v.Tag = 630 and v.SbFld = 'a'  inner join location l  on b.RecID = l.RecID   where b.Tag = 245 and b.SbFld = 'a'  ";
            connection = new SqlConnection(connetionString);
            connection.Open();
            cmd = new SqlCommand(sql, connection);

            // Create a fill a DataTable 
            DataTable dt = new DataTable();
            adapter.SelectCommand = cmd; ;
            adapter.Fill(dt);
            // Loop to go through database, then add to Solr 
            foreach (DataRow dr in dt.Rows)
            {
                intCount++;
                TrackInfo ti = new TrackInfo();
                ti.title = dr["title"].ToString();
                ti.Author = dr["author"].ToString();
                ti.AccessionNo = dr["AccessionNo"].ToString();
                ti.location = dr["location"].ToString();
                ti.ClassNo = dr["ClassNo"].ToString();
                ti.status = dr["status"].ToString();
                ti.MeetingName = dr["MeetingName"].ToString();
                ti.Uniformtitle = dr["Uniformtitle"].ToString();
                ti.publisher = dr["publisher"].ToString().Trim();

                solr.Add(ti);
                intCount++;
            }
            try
            {
                sol.r.Commit();
            }
            catch (Exception e)
            {
                return "The Solr load failed.  Function solr.Commit() failed within SolrUtil.UploadToSolr(). Message: " + e.Message;
                throw;
            }

            // Clean up resources and return record count 
            connection.Close();
            return "Solr has been updated Completed! " + intCount + " tracks were loaded.";
        }

    }

}


above  display the bold text that causes an error please give me some solution for it.

Mauricio Scheffer

unread,
Sep 6, 2016, 6:39:16 PM9/6/16
to SolrNet
Hi,
According to your class definition, TrackInfo only has properties "Name" and "OtherFields". 
It doesn't have any of the other fields you're trying to use.
This seems to be a question about C#. Please use stackoverflow instead.

Cheers,
Mauricio
Reply all
Reply to author
Forward
0 new messages