0

This seems obvious but I cannot see an easy way to to do this.

I have written a C# Program in LinqPad and it runs well, is there a guide for moving this to a Visual Studio Console Program.

A simple program such as this:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DataContext dataContext = this;
            var products = dataContext.GetTable<Product>();
            var query = from p in products
                        select p;

            query.Dump();

        }
    }
}

produces these errors:

Error 1 The type or namespace name 'DataContext' could not be found (are you missing a using directive or an assembly reference?) c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs

Error 2 Keyword 'this' is not valid in a static property, static method, or static field initializer c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
Error 3 The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?) c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 14 49 ConsoleApplication1

I must have to add some references, add a connection to the database, I just need a guide for what to add to my project but I cannot find one.

Community
  • 1
  • 1
Rich Baker
  • 33
  • 4
  • 1
    For a C# program, you replace the existing main method that Visual Studio created with the one from C# and paste all the other functions and classes under it. What is the problem you're having? – Frank van Puffelen Oct 30 '14 at 16:24
  • I have added some sample code and errors, thanks – Rich Baker Oct 31 '14 at 15:01
  • 1
    Ah... in that case you are probably looking for this: http://stackoverflow.com/questions/15359089/how-can-i-use-linqpads-generated-context-in-visual-studio and http://stackoverflow.com/questions/8140385/moving-from-linqpad-to-a-proper-visual-studio-project – Frank van Puffelen Oct 31 '14 at 15:31
  • Thanks that helps a lot, not sure how i missed it:-) – Rich Baker Oct 31 '14 at 18:46
  • You're welcome. I voted to close as a duplicate, since the answer in the linked question is probably all that you needed. – Frank van Puffelen Oct 31 '14 at 19:45

0 Answers0