简体   繁体   中英

Best way to store ASP.NET 4.5 MVC user data

I'm currently creating a web application using ASP.NET 4.5 MVC with MySQL backing my models.

Upon first login (and whenever they want to afterwards), the user enters their persistent information required for the web app (name, DoB, address, etc.) There will be a couple to a few dozen settings which are required, and I've heard that best practice dictates that even going past as few as 10 columns in a table calls for reevaluation of your paradigm.

Let's say theorietically that I could break the settings down into different types. Would there be any performance/organization/usability/etc. benefit from creating different tables for each different section?

Follow up question: should persistent user data be stored in the same table as your table of users, or should Settings have its own table? I notice that there is an AspNetUsers table which stores some basic information. Could I use this to store settings?

Thank you!

In my opinion, there is 0 gain on breaking all the user information on different tables. Do it only if you have some 1:N relation, but there is no problem if you use a single table with a lot of columns.

If you use Entity Framework and Asp.Net Identity, it's possible to extend your AspNetUsers table with custom information. Just create a class that extends from IdentityUser:

public class User : IdentityUser
{
  [MaxLength(50)]
  [Required]
  public string MyAdditionalData { get; set; }

  [Required]
  public int Age { get; set; }
}

And then in the Context class:

class YourAppContext : IdentityDbContext<User>
{
  public YourAppContext()
    : base("YourAppContext")
  {

  }
}

Using migrations, Entity Framework is capable to add/modify columns as requested, based on this class.

Greetings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM