locked
How to save single entity/class data to multiple table RRS feed

  • Question

  • User1183902823 posted

    so tell me how could i design whole things. suppose i have a registration class what has so many properties like

    Account information
    ----------------------
    First Name
    Surname
    Company Name
    Contact Number
    Email :
    Password
    Confirm Password

    Billing information
    ----------------------
    Address1
    Address2
    Town/City
    County/State
    PostCode
    Billing Country

    i have one customer class which has many properties for account and billing information. now i want when i will save customer data by EF then account info will be saved in customer table and billing info will be saved in address table. so tell me how could i do this mapping when i am working with EF db first and code first.

    i found one relevant article link https://dukhabandhu.wordpress.com/2014/11/12/table-and-entity-splitting-in-entity-framework-code-first/

    https://blogs.msdn.microsoft.com/simonince/2009/03/23/mapping-two-tables-to-one-entity-in-the-entity-framework/

    i think this link is close to my requirement https://dotnetfalcon.azurewebsites.net/stackoverflow-adventures-entity-framework-code-first-advanced-mapping-scenarios/

    they are showing that we must have two class having parent-child relationship then we can save to multiple table.

    please discuss with a sample code. thanks

    Thursday, January 18, 2018 9:24 AM

Answers

All replies

  • User-359936451 posted

    Hello, the first part of the design is a discussion of the data relationship. It would be best if you could explain in thorough things like whether or not multiple records in the Account Information table (tbl1) would have duplicate records in the Billing Information table (tbl2). This could be the case for example if a father and son both records in tbl1 in which case the associated record in tbl2 would be identical. This may be an acceptable situation, but your tbl2 definition really has no defined fields other than address, in which case it would more often be included in tbl1 as perhaps Contact or Person or Student or Patient or Account Manager,  as examples.

    Relationally, both tables should have a keyID field, a value that can be used to uniquely identify a record in the table. Or based on the relationship, a foreign keyID in tbl2 which would be associated with the keyId of tbl1.

    Here is a fairly simple starting point of these concepts....

    https://www.lucidchart.com/pages/database-diagram/database-design

    Thursday, January 18, 2018 9:49 PM
  • User1183902823 posted

    account info will be saved in customer table and billing info will be saved in address table. customer and address table will have one-to-one relation.

    thanks

    Friday, January 19, 2018 7:58 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 19, 2018 8:56 AM