How to make string as primary key in entity framework!

I have a legacy table containing employee name and employee id. Now the employee id is in char because it can hold values starting with an alphabet. Employee id is the only unique field available in the table.

Now I am using a view to capture the data from the table (It is in a separate database). But my entity framework is refusing to identify the view due to the lack of int primary key.

Any solution to this would be highly appreciated as I can not touch the legacy table.

Answers


But my entity framework is refusing to identify the view due to the lack of int primary key.

I doubt it. The EF supports strings as PKs.

But views, of course, can't have PKs at all. Which means you have to do some extra work when using them with the EF, especially if you make them updatable. Here's how.


Create another column that is an int and use that as the primary key. The business users, don't need to know about that key.

My guess is the end application uses an Employee Id with charters. Like first and last initial plus hire date, something like DB012210.

How the table is done internally won't matter to the calling application so you can add another field as the real primary key which is an int. Then just put a unique constraint on the current EmployeeId, but not really use it as the primary key.


Need Your Help

Rails Routing with Query String

ruby-on-rails routing rest query-string

I have a problem where I need values passed in from a GET request and I don't know how to set up the routing definition.

Error C2679 - C++ - No Operator Found

c++

I was wondering what was causing this error, I am trying to get it to import data from an external file and use it.