error : The type or namespace name 'SolrField' could not be found (are you missing a using directive

37 views
Skip to first unread message

Mansuri Shahrukh

unread,
Jun 4, 2016, 5:08:11 AM6/4/16
to SolrNet

I am using below code for it and its give an error that Error The type or namespace name 'SolrField' could not be found (are you missing a using directive or an assembly reference?)
 public class TrackInfo {
            [SolrField("id")]
            public string Id { get; set; }

            [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
            {
                solr.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.";
        }

    }

}
please give a solution for it .

Mauricio Scheffer

unread,
Jun 6, 2016, 6:35:40 AM6/6/16
to SolrNet
SolrField is in the SolrNet.Attributes namespace.
Reply all
Reply to author
Forward
0 new messages