1
What are the errors or inappropriate practices in this code?
static void Main(string[] args)
{
using (var db = new AccountingSystemContainer())
{
var invHeader = db.InvoiceHeaderSet.Create();
var invDetail = db.InvoiceDetailSet.Create();
invHeader.Total = 150m;
invDetail.ItemDescription = "Algum Item";
invDetail.Price = 75m;
invDetail.Quantity = 2;
invHeader.InvoiceDetail.Add(invDetail);
db.InvoiceHeaderSet.Add(invHeader);
db.SaveChanges();
}
}
public partial class InvoiceDetail
{
public int InvoiceDetail_Id { get; set; }
public string ItemDescription { get; set; }
public int Quantity { get; set; }
public decimal Price { get; set; }
public int InvoiceHeaderInvoiceHeader_Id { get; set; }
public virtual InvoiceHeader InvoiceHeader { get; set; }
}
public partial class InvoiceHeader
{
public InvoiceHeader()
{
this.InvoiceDetail = new HashSet<InvoiceDetail>();
}
public int InvoiceHeader_Id { get; set; }
public decimal Total { get; set; }
public virtual ICollection<InvoiceDetail> InvoiceDetail { get; set; }
}
public partial class AccountingSystemContainer : DbContext
{
public AccountingSystemContainer()
: base("name=AccountingSystemContainer")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<InvoiceHeader> InvoiceHeaderSet { get; set; }
public virtual DbSet<InvoiceDetail> InvoiceDetailSet { get; set; }
}