none
why am I getting these errors? RRS feed

  • Question

  • This is my first attempt at pulling from a db using LINQ to SQL.  

    Error 1 The type or namespace name 'Column' could not be found (are you missing a using directive or an assembly reference?)

    Error 2 The type or namespace name 'ColumnAttribute' could not be found (are you missing a using directive or an assembly reference?)


    I get these errors for each of the things that are italicized(both the tables and columns).  There are arrows to the right to make them easier to identify

    Can someone please help me to understand what I am doing wrong?

    Thanks in advance.

    ---------------------------------------------------------------------------------

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace LINQ_play
    {
        [Table(Name="Clip")]                  <----
        public class Clips
        {
            [Column(IsPrimaryKey = true)]    <----
            public int ClipID;

            [Column]                                    <----
            public string ClipUser;

           }
        
        class Program
        {
            static void Main(string[] args)
            {

                Console.WriteLine("This will display stuff from the db using LINQ.");

                        
                 // DataContext takes a connection string 
                DataContext db = new DataContext("C:\\Databases\\ClipStorage.mdf");
                // Get a typed table to run queries
                Table<Clip> Clips = db.GetTable<Clip>();
                // Query for customers from London
                var q =
                   from c in Clips
                   where c.ClipID != null
                   select c;
                foreach (var myClips in q)
                    Console.WriteLine("id = {0}, User = {1}", myClips.ClipID, myClips.User);
                
                Console.ReadLine();


            }
        }
    }

    Thursday, April 2, 2009 8:12 PM

Answers

  • TableAttribute, ColumnAttribute etc are defined in System.Data.Linq.Mapping, and the DataContext is in System.Data.Linq. You need to add using statements for these namespaces, or use fully qualified references to them...
    Kristofer - Huagati Systems Co., Ltd. - www.huagati.com
    Friday, April 3, 2009 1:21 AM
    Answerer

All replies

  • TableAttribute, ColumnAttribute etc are defined in System.Data.Linq.Mapping, and the DataContext is in System.Data.Linq. You need to add using statements for these namespaces, or use fully qualified references to them...
    Kristofer - Huagati Systems Co., Ltd. - www.huagati.com
    Friday, April 3, 2009 1:21 AM
    Answerer
  • I added the using statements that you suggested.  It caused two more errors pertaining to the linq stuff

    I corrected this by also adding a reference to  Systm.Data.Linq in the project.   

    I don't understand why the two using statements alone didn't get rid of the errors though.


    Thursday, April 9, 2009 11:07 AM