Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThanks, sure setting the value in code is fine but thats not the problem. Imagine a scenario with 20+ different applications writing data to the database. The DB constraint says "you have to supply a valid value for this column". It would be nice to have this constraint respected by the ORM as I cant gaurantee that every app is implemented correctly. This type of feature has been around for 20+ years. If the field is not dirty, dont write it to the DB or throw. Dont just write arbitrary defaults from the framework to the DB.
      singulars
    2. CO@bic: The constraint is respected in the sense that all properties for a *new* object are dirty and for updates only changed columns are sent to DB in an update command. The type of constraint check was only necessary because in a relational DB you *can* set individual columns when creating a new row. In an ORM (and also OO databases) you can't, thus the constraint check isn't necessary. Maybe it's an example of an "object-relational impedance mismatch": a simpe data type with no default value doesn't exist on the "O" side like a column with "no default" on the "R" side.
      singulars
    3. CO@bic: Another point: Consider you work with POCOs. An object is "somewhere" created, outside of the context, for instance in another assembly or it even comes from any kind of remote service, and the developer at the other side of the wire has explicitely set `Bar` to 0 because it's the valid value he wants to store. How could EF recognize if this is a "default value" created in the object constructor or if it has been set explicitely in code? It can't I think. This kind of detection if the value has been set explicitely or not is impossible, at least with POCOs.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload