Using Linq to SQL in asp.net 5 MVC 6 - asp.net

Can I use Linq to SQL in asp.net 5 mvc 6?
There is no "Linq to SQL Classes" in "Add New Item" form
I know its not supported in dot net core 5 but I don't need dnx core 5 and cross platform feature. I'm ok with dnx core 4.5.1
How can I add Linq to SQL Classes file (.dbml) to MVC 6 Project?

To add Linq To SQL Classes file, you have to add Class Library project to your solution. Now you can add Linq to SQL Classes (.dbml file) to this project.
Then add reference to this Class Library from your main project.
NOTE: you can not use dnxcore 5 in this way. Your main project should use dnx 4.5.1 and class library should use dotNet framework 4.5.1 as target framework.

To solve this problem, in VS just go to Tools - Get tools and features - Individual components - Select LINQ to SQL tools and then click on Modify.

Related

.NET 5 WPF EntityFramework with SQL Compact Edition

Is there a way to use EF with SQL Compact database on the new .NET 5 Windows Framework?
I tried it, but I couldn't make it workable.
Is this library supported in .NET 5?
EntityFrameworkCore.SqlServerCompact40 (looks empty the package folder)
I cannot access to the optionsBuilder.UseSqlCe(#"Data Source=C:\data\Blogging.sdf"); method.
If it is not supported, can I use EF with CE in .NET Core 3.1?
The library only supports EF Core 2.2.
If I get a sponsor I am willing to update.
You can use SQLCE with raw ADO.NET and .NET 5.
See more info here; https://erikej.github.io/sqlce/2020/08/17/netcore-sql-compact.html

Upgrading .NET Framework 4.5 to 4.6.1 causes errors in Entity Framework classes

IDE :: VS.NET 2015
Version Upgrade :: 4.5 To 4.6.1
My asp.net solution contains more than 30 projects inside. I have upgraded the targeted framework to 4.6.1 and now i am getting these tons of error in EF classes. The existing EF version is 6.0.
Please suggest how to fix these errors cropped up from the EF classes. Should i upgrade the EF version also from the Nuget console also.
If you have any models created with the EF Designer, you will need to update the code generation templates to generate EF6 compatible code.
Delete existing code-generation templates. These files will typically be named .tt and .Context.tt and be nested under your edmx file in Solution Explorer. You can select the templates in Solution Explorer and press the Del key to delete them.
Note: In Web Site projects the templates will not be nested under your edmx file, but listed alongside it in Solution Explorer.
Note: In VB.NET projects you will need to enable 'Show All Files' to be able to see the nested template files.
Add the appropriate EF 6.x code generation template. Open your model in the EF Designer, right-click on the design surface and select Add Code Generation Item...
If you are using the DbContext API (recommended) then EF 6.x DbContext Generator will be available under the Data tab.
Note: If you are using Visual Studio 2012, you will need to install the EF 6 Tools to have this template. See Get Entity Framework for details.
If you are using the ObjectContext API then you will need to select the Online tab and search for EF 6.x EntityObject Generator.
If you applied any customizations to the code generation templates you will need to re-apply them to the updated templates.

Asp.net 5 mvc 6 Entity Framework 7 database first

I noticed that this type of project does not support files edmx.
What is the right way to develop a project in Asp.net 5 MVC 6 using Entity Framwork 7?
Currently(as of EF 7, RC1) Database First support is still in development. More info on roadmap page here and on EF Design meeting notes here.
Since this is in development there are ways to try this and more info and tutorial on commands can be found at official documentation page here.
The problem is that EF7 kill EDMX. You now have Code First-style POCOs tied to an existing database, without an EDMX file in sight. The EF Power Tools Visual Studio extension can be installed to generate all of this directly from existing database.EF Power Tools Visual Studio extension actually doesn't support vs 2015

Difference between EF.SqlServer and EF.SqlServerCompact

I want to install Entity Framework in my ASP.NET 5 MVC project using project.json.
In the dependencies section I start typing EntityFramework and I only see
"EntityFramework.SqlServerCompact": "6.1.3" instead of "EntityFramework.SqlServer": "6.1.3".
What is the reason for this and what effects will this have?
Are there limitations in the compact version?
If I create a new ASP.NET 4 project with MVC and install EntityFramework then I see the EntityFramework.SqlServer reference installed and not the compact.
EntityFramework.SqlServerCompact is for interacting with SQL CE. It's a single file based database. If you're dealing with MS SQL Server, that's definitely not what you want. You want EntityFramwork 6.1.3, there is no EntityFramework.SqlServer.

SQL Server 2012 and .NET Framework 4.0

I have a server which configured for SQL Server 2008 R2 and ASP.NET 4.0.
The hosting company won't support .Net Framework 4.5 and SQL Server 2012 and latest Entity Framework.
I have created my website with .Net Framework 4.5 and latest Entity Framework 5. How can I change the publish settings to old server execute that ?
Change the Target Framework of the Website, In Solution Explorer right click the Website select 'Properties'. In the dialog that appears select Application now change the Target Framework to 4.0 and Publish.
You need to change the Target Framework for your website.In Visual Studio (with your website project selected) go to Project > Settings. Change Target Framework from .Net Framework 4.5 to .Net 4. Then rebuild all and test your app.
If it's all working OK you can then publish to your web host as normal.
The above 2 answers are correct. Additionally, many hosting companies do not support the MVC or EF dll's of any version. There is any easy work around to this. As long as you can get your code to compile in Visual Studio 2010 using .NEt 4.0, right click on your project and click 'Add Deployable Deployable Dependencies'. Check the boxes for the dll's groups you will need and they will be added to your project so they can be deployed with your website.
When installing EF5 from Nuget it will install EntityFramework.dll assembly version 5.0.0.0. if your app is targeting .NET Framework 4.5 or EntityFramework.dll assembly version 4.4.0.0 if your app is targeting .NET Framework 4. The difference between these is that EF5 for .NET Framework 4 is scoped down to what is supported by the core assembly (System.Data.Entity.dll) that is a part of .NET Framework (most notably on .NET Framework 4 you will get no enums, spatial types etc.). If you change the target after installing EntityFramework then you most likely need to uninstall what you have and install again to get the right version of the EntityFramework.dll.
you just create a new project in framework 4 and add existing items from the right click in solution in project

Resources