In entity framework, how to make a string the main key!

entity-framework

Question

Employee name and employee id are in a legacy database I have. Because char may carry values that begin with an alphabet, the employee id is now in this format. The only distinct field in the database is employee id.

I'm currently utilizing a view to extract data from the table (It is in a separate database). But since there is no int primary key, my entity framework won't recognize the view.

As I am unable to touch the heritage table, any solution would be very appreciated.

1
6
1/22/2010 1:43:00 PM

Accepted Answer

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

I have my doubts. Strings are supported as PKs by the EF.

However, views obviously cannot have any PKs. As a result, utilizing them with the EF requires some more effort, particularly if you decide to make them updateable. This is how..

6
1/22/2010 2:01:00 PM

Popular Answer

Use an additional int-based column as the main key by creating it. Users who do business don't need to be aware of that key.

My best guess is that the final application utilizes a charter and an Employee Id. similar to DB012210, first and last initials with employment date.

The caller program won't care how the database is organized internally, so you may add another field as the true primary key, which is an int. Then just utilize the current EmployeeId as a unique constraint rather than as the main key.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow