0

I use ASP.NET Identity in an MVC project and I need to create entity relation between ASP.NET Identity AspNetUsers entity and my custom tables. As it is known, AspNetUsers table uses string for Id field and there is GUID values in this Id field. However, I am not sure about the issues below:

1) What data type should I use in my custom classes in order to create PK/FK relation? string or GUID?

2) How can I make this custom Id field to be generated automatically for every new record? Is it also possible to make it sequential so that the records can be sorted?

0

1 Answer 1

1

1-You should use string. (see this)

If you open the edmx you see that Id(GUID) in AspNetUser is string.

2-You can use constructor in model and generate GUID filed in it like this:

public partial class Student
{
    public Student()
    {
        Id = System.Guid.NewGuid().ToString();
    }
    //Other fileds
}

3- for Sequential Guid Generator see this.I suggest UuidCreateSequential.

Sign up to request clarification or add additional context in comments.

1 Comment

Selam Ali, Thanks for reply. In that case: 1) Ok, I use string and keep GUID values in it. But I am not sure if I have to use anything special in this Entity. Is your example is suitable for it? 2) Could you please give an example implementation? 3) There are several answer on that page. Which one do you suggest?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.