forked from felipeleusin/MvcKickstart
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Jon Knopp edited this page Feb 11, 2015
·
5 revisions
You can have any field map to nvarchar by decorating the property with the [StringLength(xx)] attribute For example:
public class TestTable {
[AutoIncrement]
public int Id { get; set; }
[StringLength(50)]
public MyEnumType MyEnumProperty { get; set; }
}
SQL types are defined in DbExtensions.cs. Look near the bottom for the TypeToSqlType field.
// Auto incrementing primary key Id. The [PrimaryKey] attribute is inferred when using [AutoIncrement]
public class TestTable {
[AutoIncrement]
public int Id { get; set; }
}
// Guid primary key
public class TestTable {
[PrimaryKey]
[Default("newSequentialId()")]
public Guid Id { get; set; }
}
public class TestTable {
[AutoIncrement]
public int Id { get; set; }
}
public class OtherTestTable {
[AutoIncrement]
public int Id { get; set; }
[References(typeof(TestTable))]
public int TestTableId { get; set; }
}
// By default, we will use plural table names based on the name of the class.
// You can override this by using the table attribute from the System.ComponentModel.DataAnnotations.Schema namespace
[Table("TestTable")]
public class TestTable {
[AutoIncrement]
public int Id { get; set; }
}