0

A colleague and I have been trying to augment an existing database with entity framework code first and we are having no luck achieving what we need to do.

In a nutshell, we have an existing database which has a user type InternetUser. We are upgrading the project and trying to integrate the MembershipReboot code. That code has a concept (and entity) of a UserAccount. So, we decided that we would connect these two types with a foreign key in the InternetUser object that references the primary key (a GUID) of the relevant UserAccount object.

We created our entities by using the entity framework Power Tools and reverse engineering. We then manually connected the InternetUser type with the UserAccount in MembershipReboot by including a UserAccountId property.

The complexity in this migration comes from the fact that some hashing (cryptography) code in the MembershipReboot library needs to run whenever a UserAccount is created. I am not quite sure how to do that in the seed method using EF code first. So, it is not just a case of running a SQL script when seeding. Some C# needs to run to create the user using MembershipReboot.

If anyone has tried to accomplish something similar, I would love to hear from them and how they solved the problem.

Guy
  • 1,434
  • 1
  • 19
  • 33
onefootswill
  • 3,707
  • 6
  • 47
  • 101
  • Why is running C# code in the `Seed` method a problem? Have you inherited `DbMigrationsConfiguration` and overridden the `Seed` method there? http://blog.oneunicorn.com/2013/05/28/database-initializer-and-migrations-seed-methods/ – Colin Nov 18 '13 at 09:52
  • @Colin The problem is, we need to somehow update each existing InternetUser with the PK of a UserAccount that needs to be created there and then by invoking the CreateUser method of the MembershipReboot library. That needs to be inserted into the FK UserAccountId. This needs to be done for each and every InternetUser, presumably in the same iteration. – onefootswill Nov 19 '13 at 07:03
  • Can you show us the code you currently have in your override of `DbMigrationsConfiguration.Seed` ? – Colin Nov 19 '13 at 10:11
  • 1
    This question is [too broad](http://stackoverflow.com/help/on-topic). There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. – Jørgen R Mar 19 '15 at 14:41

0 Answers0