3

How can I add a Linq to Sql file in Microsoft Asp.Net 5 with Mvc 6. see the screenshot below. There is no way where I can find this Linq to Sql file. As well there is no C# tab at the side??

enter image description here

When I open the project on Asp.Net 4 with Mvc 5 there is this C# tab, as well as the Linq to sql file.

9
  • Are you sure Linq to SQL is a good choice for new project in 2016? Commented Jan 16, 2016 at 17:52
  • Should I consider using EF 7? Commented Jan 16, 2016 at 17:53
  • EF7 looks very promising, but it's still not released. You can check their roadmap. Choosing ORM is an interesting question and it really depends on your application needs. I think you can google for some comparisons between ORM's. Commented Jan 16, 2016 at 18:03
  • @AleksandrIvanov to be fair, neither is aspnet5. Both are RC1 and 'supported`. I'd agree that as LINQ to SQL's been pretty unloved my MS since 2008 that it wouldn't be on my list to use in a new project. Commented Jan 16, 2016 at 18:23
  • 1
    This was already answered here Commented Jan 16, 2016 at 19:07

1 Answer 1

4

Duplicate here, however I've tried to add more step by step instructions so that it could help you and others.

Right click on src and Add > New Project. Select Class Libarary. Take note of the .NET Framework (I'm using 4.6 here), as you will have to match that with your main project.

Add new project

The class library should appear in your solution.

Solution Explorer

Right click on the class library (or a sub folder where you want the Linq To Sql Classes), and Add > New Item. In the data tab (on the left), it should have the item LINQ to SQL Classes

Add Linq To Sql Classes

Configure your LINQ to SQL.

LINQ to SQL

In your main asp.net-5 web application, make sure your project.json is setup so that it's using the same .NET Framework as your Class Library (check first step). I'm using 4.6 here.

"frameworks": {
    "dnx46": {
    }
},

Still in your main asp.net-5 solution, right click on References > Add Reference.

Add Reference

Add the Class Library reference.

Reference

I hope this helps.

Sign up to request clarification or add additional context in comments.

6 Comments

No connection string named 'NORTHWNDEntities' could be found in the application config file. error occurred when binding the mentioned way.i'm using entity.
It cannot find the connection string, so you will have to set it up properly in your application.json file. "Data": { "DefaultConnection": { "ConnectionString": "Server=.;Database=YOURDB;integrated security=true;Trusted_Connection=True;Persist Security Info=true;MultipleActiveResultSets=true" } } and in your startup.cs file (after loading your appsettings.json) you can reference its like so: Configuration["Data:DefaultConnection:ConnectionString"]) I hope this helps.
Thanks, i tried, but it can't work. can you please share any document link.
I'm not sure what you problem is and there's not enough information to go on. Please ask the question on stackoverflow with your setup and I'll answer it.
LINQ to SQL is still not listed. It is now 2017 and I am using VS2017. What the hell are they thinking? EF is slow and heavy. If I want business logic I'll put it in the middle tier ie in the web service implementation.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.