|
-
Jul 23rd, 2015, 06:31 PM
#1
Thread Starter
PowerPoster
[RESOLVED] MVC5 Code-First Database Schema
Two things, I am new to MVC and need to confirm if this looks right. Also I am told by the IDE that a public string is not nullable. The database would have a nullable varchar type.
vb Code:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace NotaryNet.Models
{
/// <summary>
/// Registration Database Structure.
/// </summary>
/// <remarks>
/// 1. Company name during registration must be unique. Not allow same company name to be registered.
/// 2. Initial registered user is automatically assigned to the Admin Role and they can register/create additional users as needed.
/// A. If any additional user accounts are created by the Admin, they will be added to the Users role.
/// 3. Each SystemUser has their own respective information about them in the SystemUsersInfo table.
///
/// 1. Company and SystemUsers share a PK (CompanyID) and FK (CompanyID) relationship.
/// 2. SystemUsers and SystemUsersInfo share a PK (UserID) and FK (UserID) relationship.
/// </remarks>
[Table("Companies")]
public class Register
{
[Key]
public int CompanyID { get; set; }
public string CompanyName { get; set; }
public bool IsActive { get; set; }
public virtual ICollection<SystemUsers> SystemUsers { get; set; }
}
[Table("SystemUsers")]
public class SystemUsers
{
[Key]
public int UserID { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public bool IsActive { get; set; }
[ForeignKey("CompanyID")]
public virtual ICollection<SystemUserInfo> SystemUserInfo { get; set; }
}
[Table("SystemUserInfo")]
public class SystemUserInfo
{
[Key]
public int SystemUserInfoID { get; set; }
public string NamePrefix { get; set; }
public string FirstName { get; set; }
public string? MiddleInitial { get; set; }
public string LastName { get; set; }
public string? NameSuffix { get; set; }
[ForeignKey("UseID")]
}
}
-
Jul 23rd, 2015, 10:23 PM
#2
Thread Starter
PowerPoster
Re: MVC5 Code-First Database Schema
-
Jul 27th, 2015, 07:16 AM
#3
Re: [RESOLVED] MVC5 Code-First Database Schema
Well that didn't take long I know what you mean, though, as I found it frustrating at first. It does get easier so it's worth sticking with it.
Also I am told by the IDE that a public string is not nullable.
You don't need to set a string to be nullable in order to generate a nullable varchar. A string will generate a nullable varchar by default and you need to decorate the property with a Required attribute if you want the field to be non-nullable.
Ints, boleans and numerics behave the opposite way and generate a non-nullable type by default. If you want them to be nullable you have to declare them as nullable types.
That inconsistency is one of the easiest things to get wrong at first.
Also, beware that foreign keys are all set to cascade deletes and updates by default (which is absoluetly the wrong choice for a default IMO) and you have to explicitely set them to refuse delates and updates.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|