-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Steps to reproduce
Run this and see what happens for tables without a primary key:
Scaffold-DbContext "Server=xxxx;Database=yyyy;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer
The issue
Hi. The code generation is pretty cool and a big time saver. While EF might not be able to handle it when there is no primary key, it would be awesome if the code generated the class files for the tables anyway. And even go all the way or as far as it can in the DBContext file. That would still allow us to continue with manual changes (if there is a database or political reason that we can not add a primary key) or just continue with adding our own queries and not using some of the built-in functions like .Find. I presume that we still can query with EF without a primary key. Maybe we can even do updates and inserts? I think that the primary key absence would only affect some features like caching or whatever.
Long term I'd guess if there is no primary key, or if the key contains multiple fields, you can just have the system generate its own such thing in memory composed of the combination of all the fields, maybe produce a unique hash code from them. Obviously slow, but provides the functionality, should someone choose to use it.
But anyway, the point of this ticket is at least to allow the PowerShell scaffolding script to at least output the tables into Classes and do as much as you're willing in the DbContext because just that would be a big help for situations where the DB schema is just not entirely in our control. This example is a schema that's used by an ERP software, and we know how great some of those old ones are at keeping database relations OUT of the database. :)
Further technical details
EF Core version: 1.0.0-rc2-final
Operating system: Win10
Visual Studio version: 2015
Other details about my project setup:
Using: Scaffold-DbContext "Server=xxxx;Database=yyyy;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer