user3523890
user3523890

Reputation: 49

C# Connect database to Visual Studio project

I have just started studying databases and now I'm trying to connect to a SQL database with Visual Studio. I made the main model. There are tables and stuff. Now I created a console application. I made reference to the project with the data (where the diagram with tables is). But when I try to compile the project I get this error

error CS1502: The best overloaded method match for 'System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction(string, params System.Data.Entity.Core.Objects.ObjectParameter[])' has some invalid arguments

and this error

error CS1503: Argument 2: cannot convert from 'System.Data.Objects.ObjectParameter' to 'System.Data.Entity.Core.Objects.ObjectParameter[]'

And on the other project with the data I get this error

error CS0006: Metadata file 'C:\Users\United\Documents\Visual Studio 2012\Projects\C#\EntityFrameworkDemo.Data\EntityFrameworkDemo.Data\bin\Debug\EntityFrameworkDemo.Data.dll' could not be found

I couldn't find a solution to any of the errors. Can you suggest something?

Here is the sample code that I'm trying to run:

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

namespace EntityFramework
{
    class Program
    {
        static void Main(string[] args)
        {
            NorthwindEntities db = new NorthwindEntities();

            foreach (var customer in db.Customers)
            {
                Console.WriteLine(customer.ContactName);
            }
            db.Dispose();
        }
    }
}

Upvotes: 0

Views: 853

Answers (1)

Martin Costello
Martin Costello

Reputation: 10882

It looks like you have conflicts between the types defined in the Sysytem.Data.Entity assembly and the EntityFramework assembly. If you're using EF 6 or later, remove all references to System.Data.Entity and try recompiling. You may need to remove some lingering using statements for those types as well.

Upvotes: 1

Related Questions