We need to use both two namespace in order to use table or key attribute in entity framework.
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("tab_userprofle")]
public class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
}</div>
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
[Table("tab_userprofle")]
public class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
}</div>
System.ComponentModel.DataAnnotations Attributes:
Attribute | Description |
---|---|
Key | Mark property as EntityKey which will be mapped to PK of related table. |
Timestamp | Mark the property as a non-nullable timestamp column in the database. |
ConcurrencyCheck | ConcurrencyCheck annotation allows you to flag one or more properties to be used for concurrency checking in the database when a user edits or deletes an entity. |
Required | The Required annotation will force EF (and MVC) to ensure that property has data in it. |
MinLength | MinLength annotation validates property whether it has minimum length of array or string. |
MaxLength | MaxLength annotation maximum length of property which in turn sets the maximum length of column in the database |
StringLength | Specifies the minimum and maximum length of characters that are allowed in a data field. |
System.ComponentModel.DataAnnotations.Schema Attributes:
Attribute | Description |
---|---|
Table | Specify name of the DB table which will be mapped with the class |
Column | Specify column name and datatype which will be mapped with the property |
Index | Create an Index for specified column. (EF 6.1 onwards only) |
ForeignKey | Specify Foreign key property for Navigation property |
NotMapped | Specify that property will not be mapped with database |
DatabaseGenerated | DatabaseGenerated attribute specifies that property will be mapped to Computed column of the database table. So the property will be read-only property. It can also be used to map the property to identity column (auto incremental column). |
InverseProperty | InverseProperty is useful when you have multiple relationships between two classes. |
ComplexType | Mark the class as complex type in EF. |