简体   繁体   中英

save entity with null reference

我想知道,例如我是否有像客户和客户地址的实体和地址是客户的参考如果我找不到与实体键匹配会发生什么样的客户将需要保存地址null什么会发生在提交中,我会转储?

It depends on what technique are you using and what DB schema have you defined. Typically object graph is represented in relational DB as a number of tables with foreign keys that represent references between objects. If the field (the FK) is nullable, so you can save customer without address. Otherwise constraint violation exception will be thrown.

If you need more information please post some of your code and explain what is the persistence technology that you are using.

Imo, if you db allows nulls in the address column (and no FK constraints exists), it will save nulls. Else, it should fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM