Default value for property using Data Annotations in Entity Framework

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

Question

I have a model like this

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's a way, using Data Annotations, to set the value of a property - say Title - default to other property value, i.e. Name. Something like:

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

Popular Answer

If you want default value set it in entity default (parameterless) constructor. There is no need to have data annotation for something which you can do directly.

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