Entity Framework Core. Code-First Approach
- FK defines relationships of tables
- Navigation Property defines the type of relations: One-To-One, One-To-Many, Many-To-Many
- If FK wasn't initialized, EF creates it automatically
How To Use?
1. Design a DB on the paper
2. Set FK (FK points from the main table to the dependent table)
3. Define Navigation property
// ==========================
public class Customer
{
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
// Navigation property (or Link)
public List<Order> Orders { get; set; }
}
public class Order
{
public int OrderId { get; set; }
public string ProductName { get; set; }
public string Description { get; set; }
// Navigation property (or Link)
public Customer Customer { get; set; }
}
- FK defines relationships of tables
- Navigation Property defines the type of relations: One-To-One, One-To-Many, Many-To-Many
- If FK wasn't initialized, EF creates it automatically
How To Use?
1. Design a DB on the paper
2. Set FK (FK points from the main table to the dependent table)
3. Define Navigation property
// ==========================
public class Customer
{
public int CustomerId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
// Navigation property (or Link)
public List<Order> Orders { get; set; }
}
public class Order
{
public int OrderId { get; set; }
public string ProductName { get; set; }
public string Description { get; set; }
// Navigation property (or Link)
public Customer Customer { get; set; }
}
No comments:
Post a Comment