EF Code First - Recreate Database If Model Changes

后端 未结 3 1841
攒了一身酷
攒了一身酷 2020-12-24 15:51

I\'m currently working on a project which is using EF Code First with POCOs. I have 5 POCOs that so far depends on the POCO \"User\".

The POCO \"User\" should refer

3条回答
  •  一整个雨季
    2020-12-24 15:59

    One thing you might consider is to use a 'disconnected' foreign key. You can leave the ASPNETDB alone and just reference the user in your DB using the User key (guid). You can access the logged in user as follows:

    MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
    

    And then use the User's key as a FK in your DB:

    Guid UserId = (Guid) currentUser.ProviderUserKey ;
    

    This approach decouples your DB with the ASPNETDB and associated provider architecturally. However, operationally, the data will of course be loosely connected since the IDs will be in each DB. Note also there will be no referential constraints, whcih may or may not be an issue for you.

提交回复
热议问题