Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Problem
How to use entity framework with database tables that not have primary key.

i have old database made by SQL server 2012 i get requirement to work as entity

framework technique and mvc .

i suddenly found that more tables not have primary keys

and no relation ship between some tables for each other

so that how to solve that problem .

What I have tried:

I try with database have all tables primary key
but if i do that what problem i will face
Posted
Updated 29-Dec-18 16:22pm

1 solution

Simple. You don't.

If there's no primary key, Entity Framework can't use the table. EF MUST have a way to uniquely identify every record in the table, and that means having primary keys.

Really, you don't even want to work with "tables" that don't have keys without some ORM. It can be an elephanting nightmare to deal with.

Do not attempt to "work around" a condition like this. Just fix the data model and add keys to the tables that don't have them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900