Entity Framework Code First Using One column as Primary Key and another as Auto Increment Column

You can also do this with Data Annotations:

public class Sale
{
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    [Key]
    public string TrNo { get; set; }

    public DateTime Date { get; set; }
    public int CustomerID { get; set; }

    public ObservableCollection<SaleDetail> SaleDetails { get; set; }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)