Default value for property using Data Annotations in Entity Framework

asp.net asp.net-mvc c# data-annotations entity-framework

Question

This is the model I have.

public class MyModel
{
    public int MyModelId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string Title { get; set; }
}

I was wondering if there was a method to change the default value of a property, like Title, to another property value, like Name, using Data Annotations. the following

if(MyModel.Title == "") MyModel.Title = MyModel.Name;
1
10
6/8/2011 1:24:04 AM

Popular Answer

Set the entity default (parameterless) constructor's default value if you desire it. Data annotation is not necessary for actions that may be taken immediately.

10
6/8/2011 7:27:34 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow