Possible to set column ordering in Entity Framework

c# ef-code-first ef-fluent-api entity-framework entity-framework-6

Question

Is there a way to configure the entity framework's code-first approach to establish the database column ordering?

My entity set as a whole need to have certain standard fields for recording information.

public DateTime CreatedAt { get; set; }
public int CreatedBy { get; set; }
public DateTime ModifiedAt { get; set; }
public int ModifiedBy { get; set; }
public bool IsDeleted { get; set; }

This field will remain at the table's conclusion. Instead of maintaining these fields at the end of my model class, is there any conceivable EF setting that I can utilise to do this?

1
8
4/6/2017 5:51:30 AM

Accepted Answer

ZZZ_tmp
7
4/6/2017 6:08:49 AM

Popular Answer

Use only:

using System.ComponentModel.DataAnnotations.Schema;

Code:

[DisplayColumn("Name" , Order = 1)]
public int UserName { get; set; }

If you ordered simply this column, it will be the first one in the table unless you ordered another column with a lower order number, which in this instance is 0 (notice that column order by default accepts a huge number).



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