I am using EF with an asp.net mvc project which I am using c# for.
I am busy designing the data model now and I would like to know if there is a way to control certain properties about each property not only in the model object but also in the persisted storage (MS SQL in my case).
Here is an example of my current domain model.
public class Network
{
[Required]
public int networkID { get; set; }
[Required]
[StringLength(30, MinimumLength = 3)]
[DisplayName("Name")]
public string name { get; set; }
[Required]
[Range(0, 7)]
[DisplayName("Start Code")]
public int startCode { get; set; }
[Required]
[DisplayName("Frequency (Mhz)")]
public decimal frequency { get; set; }
//public virtual List<Block> blocks { get; set; }
//The number of used up blocks. Will increase by the block size of every newly created block.
[Required]
[Range(0, 65535)]
public int blockCounter { get; set; }
//Number of blocks within the network.
[Range(0,65535)]
public int noOfBlocks { get; set; }
}
Now the questions relating to this:
This line:
[Range(0,65535)]
public int noOfBlocks { get; set; }
Will This actully limit the int in the database to that size? Or is this purely for validation purposes?
If not how can I define certain properties about a specific attribute such as:
- If it is a primary key?
- Set a default value.
- Specify a length or range of a field.
- define if it can be null.
Basically the functionality which MS SQL offerers when creating a entry.