none
VS 2013: Walkthrough Creating LINQ to SQL Classes (O/R Designer) - Fail.."type or namespace for the datacontext is not found RRS feed

  • Question

  • Trying to self teach some code.  Of course, issue after issue.

    I am stumbling through this example on MSDN....  https://msdn.microsoft.com/en-us/library/bb384428%28v=vs.120%29.aspx

    When I get to Section: Creating Data Bound Controls... Step 5....

    Add the following code to the form, global to the form, outside any specific method, but inside the Form1 class:

    private NorthwindDataContext northwindDataContext1
        = new NorthwindDataContext();

    I get the following error...

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

    I believe I followed the example exactly.  Any guidance would be much appreciated.

    Friday, September 18, 2015 4:39 AM

Answers

  • C# is case sensitive.  You have Northwind..... it should be NorthWind....


    Lloyd Sheen

    • Marked as answer by NewbieDewbie Saturday, September 19, 2015 10:20 PM
    Friday, September 18, 2015 5:15 PM

All replies

  • Hi,

    Do you already have created a Data Connections from the Server Explorer of a Northwind database to your Sql Server? If not, then create a connection first at the Server Explorer's Data Connections. Just take a look at this picture:

     


    Friday, September 18, 2015 5:27 AM
  • HI Hardz,

    Thanks for your response and the picture to aid me.

    Yes. I do have a connection established.  I have created an Object Data Source with the Customer entity? class and I tested the connection too.

    Maybe I have put the code in the wrong spot?  I should have included the below in the original post.

    This is Form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.Linq;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace ORDesignerWalkthrough
    {
        public partial class Form1 : Form
        {
            private NorthwindDataContext northwindDataContext1 = new NorthwindDataContext();

            public Form1()
            {
                InitializeComponent();                               
            }
           
        }

    }

    Here is the first 50 lines of the NorthWind.designer.cs. I did not change any of this code.

    #pragma warning disable 1591
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.18444
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    namespace ORDesignerWalkthrough
    {
        using System.Data.Linq;
        using System.Data.Linq.Mapping;
        using System.Data;
        using System.Collections.Generic;
        using System.Reflection;
        using System.Linq;
        using System.Linq.Expressions;
        using System.ComponentModel;
        using System;
        
        
        [global::System.Data.Linq.Mapping.DatabaseAttribute(Name="Northwind")]
        public partial class NorthWindDataContext : System.Data.Linq.DataContext
        {
            
            private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
            
        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void InsertCustomer(Customer instance);
        partial void UpdateCustomer(Customer instance);
        partial void DeleteCustomer(Customer instance);
        partial void InsertOrder(Order instance);
        partial void UpdateOrder(Order instance);
        partial void DeleteOrder(Order instance);
        #endregion
            
            public NorthWindDataContext() :
                    base(global::ORDesignerWalkthrough.Properties.Settings.Default.NorthwindConnectionString, mappingSource)
            {
                OnCreated();
            }
            
            public NorthWindDataContext(string connection) :
                    base(connection, mappingSource)
            {
                OnCreated();  .... and it goes on

    Friday, September 18, 2015 8:04 AM
  • C# is case sensitive.  You have Northwind..... it should be NorthWind....


    Lloyd Sheen

    • Marked as answer by NewbieDewbie Saturday, September 19, 2015 10:20 PM
    Friday, September 18, 2015 5:15 PM
  • Lloyd,

    Bahhhhhh!    Thank you very much.  I copy pasted the datacontext snippet from the web site, but when creating the database I accidentally typed the name of the database differently than in the example.  Doh!

    Thank you   Thank you.

    Saturday, September 19, 2015 10:23 PM