none
How to create table where primary key = primary key from another table RRS feed

  • Question

  • For example I have table user

    public class User
    {
    public int UserId {get;set;}
    public string Name {get;set;}
    }

    And I have table

    public class UserPlugin1
    {
    public int UserId {get;set;}
    ...
    }
    
    public class UserPlugin2
    {
    public int UserId {get;set;}
    ...
    }
    
    

    The main thing that field UserId in plugin table should be the same as in User Table.

    I tried this but it failed

    public class UserPlugin1
    {
    public User UserId {get;set;}
    ...
    }

    Of course I can create standard primary key UserPluginId and use UserId as foreign key, but in this case i will have unneccessary field UserPluginId. That's why i decided that idea to make field wich id will be from user table is better.

    public class UserPlugin1
    {
    public UserPluginId {get;set;}
    public User UserId {get;set;}
    ...
    }


    My .NET Blog with projects and feedback.

    Since May 30, 2014 I am waiting for Microsoft fix these 2 bug. If you know how to speed them up, please help

    Tuesday, January 20, 2015 4:07 PM

Answers

  • Hello,

    >>The main thing that field UserId in plugin table should be the same as in User Table.

    If you are trying do it with Entity Framework Code First, you could check this approach in this article:

    Configure One-to-One Relationship

    You can see that in that case, the two primary keys need to be dependend.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by SmartWhy Wednesday, January 21, 2015 2:05 PM
    Wednesday, January 21, 2015 8:30 AM
    Moderator