Faker
Explore posts from servers? operator and property assigned to =null! meaning in EF core database context
yeah I see, in the DTO thing, we would have 2 queries then, like we wouldn't be able to use a single query to fetch both a subset of Book data and use that in our next query?
44 replies
? operator and property assigned to =null! meaning in EF core database context
Ok guys, just need to do small summary, please confirm whether the following is correct/add up to it if needed pls:
1.
?
is used to explicitly say that we are expecting a particular column to be null in the database context. For example, int PublishedYear
means this is a nullable field.
2. If we have reference types, like string, the default value of string and any other referenced type is null. But without the ?
, we need to provide a value. We provide a value, like null
then we just suppress the warning using the null-forigiving operator !
. (Would have been better to use a default value here @ZZZZZZZZZZZZZZZZZZZZZZZZZ ? why pls like you said either use default value or required attribute; what does the required attribute do in this case?)
3. Also, just read about the Include()
thing. Basically, the nav property which linked a particular object to another entity, that object can be null if it's not loaded; that's where it might be useful to use the ?
operator. Now, in order for the object, not to be null, we use the Include()
method which loads them "eagerly" something like that.44 replies
? operator and property assigned to =null! meaning in EF core database context
hmm so this give us another question :c : When to use the
null!
thing? Like if I've understood correctly, we are saying ok, this thing cannot be null but we are still assigning null to it but ignore the warning, we will pass a value to it later on.44 replies