views:

37

answers:

2

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.

+1  A: 

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.

David Basarab
Hi David! Thanks for your suggestion. I tried it before and it worked perfectly for me. But like I mentioned in my question that carrying on with a significant change with the legacy table is not permitted as that table is being used by a huge ERP application.
Arup Chaudhury
A: 

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.

Craig Stuntz
Thanks Craig! Your answer helped me to find my answer.The Employee id column in the legacy table has Allow Nulls property as true and so the EF refused to identify it as PK. Once I removed it everything worked fine.
Arup Chaudhury