Entity Framework와 관련된 도움이 필요합니다. 공급 업체가 존재 추가하지 않고 내 상황에 송장을 추가하는 방법 : 내가 여기에 가상 supplier
특성Entity Framework에서 컨텍스트에 추가
public class Invoices
{
public string InvoiceNumber { get; set; }
public string Department { get; set; }
public int SupplierId{ get; set; }
[ForeignKey("SupplierId")]
public virtual Supplier SupplierDetails { get; set; }
}
있다
public class Supplier
{
[Key, Column("SupplierId")]
public int Id { get; set; }
public bool IsDeleted { get; set; }
public string Name { get; set; }
[Required]
public string Address { get; set; }
public string ContactNumber { get; set; }
[Required]
[EmailAddress]
public string EmailAdd { get; set; }
}
내 질문 인 supplier
클래스의 구조의 클래스를 가지고 내 데이터베이스?
여기 이해할 수있을 것입니다 추가
public ActionResult AddInvoice(Invoices inv)
{
context.invoices.add(inv);
return View();
}
어떤 도움에 대한 내 코드입니다 - 희망 누군가가 나에게 도움이 될 수 있습니다. 감사합니다
그리고 어떤 문제가 발생합니까? 유일한 문제는'context.SaveChanges()'가 누락 될 것입니다. – Mats391
'SupplierId'가 nullable이 아닙니다. 따라서 '공급 업체'를 설정해야합니다. [이 비슷한 질문] 참조 (http://stackoverflow.com/questions/41826138/insert-first-set-of-data-to-ef-code-first-using-repository-pattern/41826550#41826550) – smoksnes
하지만 난 내 공급자 디렉토리에 존재하지 않는 경우 세부 사항을 추가해야합니다. – Neil