I am using Entity Framework in my application,so I have mapped my property objects to database objects. The property objects have been defined using Column attribute.
Now,I want to order them,but I can't find the property in Column Attribute for Order.
I have included System.ComponentModel.DataAnnotations,but still not getting it
Thanks in advance
Column order By default when creating a table with Migrations, EF Core orders primary key columns first, followed by properties of the entity type and owned types, and finally properties from base types. You can, however, specify a different column order: Data Annotations. Fluent API.
Column. Column attribute overrides the default convention. EF Code First will create a column with a specified name in the Column attribute for a given property.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
Use data annotations to use the different table and column names.
just use :
using System.ComponentModel.DataAnnotations.Schema;
Code :
[Column("Name" , Order = 1)]
public int UserName { get; set; }
Notice : cloumn arder by default takes a big number so if you ordered only this column it will be first one in the table unless you ordered another column with a lower order number which is in this case : 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With