Insert into many-to-many relationship tables

后端 未结 2 1469
死守一世寂寞
死守一世寂寞 2021-01-29 02:41

Simple scenario

[ClientTable]: ClientId, ClientName, Phone, Age
[CityTable]: CityID, CityName, Country
[ClientCityTable]: ClientCityID, ClientID, CityID

Client          


        
2条回答
  •  半阙折子戏
    2021-01-29 03:36

    From the result, it really does not matter. Both ways are correct.

    Advantages of the second (only one insertonsubmit)

    • cleaner
    • less code

    Advantage of the first one

    • for people who are new to Linq2sql easier to read/understand
    • also if there are no correct references, an insert will be done (or is this a disadvantage?, up to you)

    As you already found out, the result is the same.

提交回复
热议问题