4

We have an ASP.NET MVC5 website, I am redesigning it by creating a WebAPI using ASP.NET Core 2.1. We used Linq to SQL tools in the old project. So, I created a Class Library(.NET Framework) as a separate project, and I generated the .dbml file, then referenced it in the WebAPI. When I build the solution, I got this error

Severity Code Description Project File Line Suppression State Error CS0012 The type 'Table<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Blockquote

I added the Reference Assembly to the project (using add Reference > Browse), and the build finished successfully. When I started debugging and tried to call a GET method, I got this error.

Blockquote "Something went wrong please try again. Error: System.BadImageFormatException: Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)\r\nFile name: 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.\r\n at ProjectName.API.Common.Connectors.Connector..ctor(String userName)\r\n at ProjectName.API.ApiModels.APIViewModel.GetMethod(String userName) in C:\Users\xname\source\folder\ProjectFolder\ProjectName.API\ApiModels\APIViewModel.cs:line 73\r\n at ProjectName.API.Controllers.NameController.Method(String userName) in C:\Users\xname\source\folder\ProjectFolder\ProjectName.API\Controllers\NameController.cs:line 37\r\n\r\n" Blockquote

I went through the internet to solve both of them, but so fare nothing could solve the problem. Where am I wrong ? How to make it work ?

Is it wrong to reference .NET Framework project in a .NET Core project ? If yes, what Should I be using instead?

Edit: The main entities mapping is done by EF core 2.1. The mapping with Linq to SQL tools is just for 2 views where we have read only privilege.

Mohamed Sahbi
  • 1,065
  • 10
  • 24

1 Answers1

2

Simple. YOu do not. Linq To SQL is ancient, was abandoned WAY before the whole netstandard discussion started. As it is not netstandard it is not working on dotnet core. And as it was abandone like 15 years ago or so (yes, seriously), there is exactly zero chance of Microsoft stepping up and updating it. You should literally have moved away from that many many years ago.

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • 1
    was abandone like 15 years ago" ? if it is the case, why would they still have it and support it by documentations ? – Mohamed Sahbi Aug 03 '18 at 11:35
  • Really? https://stackoverflow.com/questions/3407565/has-microsoft-confirmed-their-stance-on-linq-to-sql-end-of-life from 8 years ago. Seriously. You are right . more like 8 years ago. Development stopped. – TomTom Aug 03 '18 at 12:04
  • 1
    I see.. but untill now nothing was so efficient as Linq to SQL tools when it comes to mapping Views. I scaffold-ed the existing db using EF core 2.1 ,but Views are from other different databases and which was hard to implement. – Mohamed Sahbi Aug 03 '18 at 12:51
  • @M.Sahbi what do you mean? EF scaffolding was always available. You probaly mean *modelling* which was abandoned *by developers* because it was harder to do than configuring contexts in code. A model forces you to put all tables in one context, when you probably don't need more than half a dozen entities in each context. Different use cases require different mappings even for the same table. – Panagiotis Kanavos Aug 03 '18 at 12:59
  • @M.Sahbi besides, you don't even need to specify all columns in the context, just keys and relations. The rest are mapped using conventions – Panagiotis Kanavos Aug 03 '18 at 13:01
  • I know that was always available. I am not talking about normal tables in the db, I am talking about "Views". I am mapping them because they are already have the only columns that my portal is supposed to see/have access to. There are no keys, and even relations are not that simple, I am talking about views having columns from different tables from different DBs – Mohamed Sahbi Aug 03 '18 at 13:21
  • 2
    worst response eva, how can you deal with stored procedures with only Entity Framework ? its a mess, you have to manually describe all the result sets... – DarioN1 Dec 13 '19 at 16:48