A value of type 'Employee?' can't be assigned to a variable of type 'Employee' because 'Employee?' is nullable and 'Employee' isn't - flutter

Error: A value of type 'Employee?' can't be assigned to a variable of
type 'Employee' because 'Employee?' is nullable and 'Employee' isn't.

.fromJson constructor your employee varable can be null as your initing it, but in model it declare like null safaty(by default). If your logic is requider this varible strongly, be shure is not null. Other way if it is not required you can use ? brfore class name, then it can be null!
Employee? employee;

Related

The parameter 'abc' can't have a value of 'null' because of its type, but the implicit default value is 'null'

#required to a property gave such ERROR:
The parameter 'lng' can't have a value of 'null' because of its type, but the implicit default value is 'null'. (Documentation)
but removing #, removes the error. how ?
I mean, the value still can be null. What does it have to do with "#" symbol.
see pictures:
You dont need to use # anymore, just use required.
({
required this.lat,
required this.lng,
})
if you like to accept null data, use DataType? varName.
String? lat;
String? lng;
More about understanding-null-safety

F# linq filter column by null value

in F# query can't make filtering by null work
role.CompanyId is nullable column
query {
for role in roles do
where (role.CompanyId = null)
select role
}
Compiler gives error Solution api.sln
Project Roles.Domain
Roles\Roles.Domain\CompanyRoles\R.fs:66 The type 'Nullable<int>' does not have 'null' as a proper value. To create a null value for a Nullable type use 'System.Nullable()'.
Can somebody help ?
This works
query {
for role in roles do
where (role.Company = null)
select role
}

PostgreSQL to Java Data Types (Grails)

I have the following (Grails) domain object:
class Country {
Integer id
char country_abbr
String country_name
static mapping = {
version false
id name: 'id'
table 'country'
id generator:'identity', column:'id'
}
static constraints = {
}}
The 'country_abbr' field within the 'country table' has type: character(2). However, whenever I am setting the domain object's data type (for 'country_abbr') to String, initialization is failing with the following exception
org.hibernate.HibernateException: Wrong column type in mydb.country for column country_abbr. Found: bpchar, expected: varchar(255)
On the other hand, leaving this type as a Java char would only retrieve the first character. Any ideas how may I map to this type? Also, what is bpchar exactly?
Thanks
Just to make this question answered. The solution is to change the country_abbr mapping:
country_abbr columnDefinition: 'char'
Reference here.

how to insert null or valid value in nullable column of database in EF 4.1

I am in scenerio where I need to inset a dateTime value in the database using the EF 4.1.
DateColumn in database in Nullable.
While creating the entity i am filling it as,
DTCLOSE = referenceProblemLog.DateClosed.HasValue ?
referenceProblemLog.DateClosed.Value.ToFeedFormatString() :
System.DBNull.Value.ToString(),
where ToFeedFormatString is an extension method.
Now problem i observed is, if I have a proper value then it is inserted correctly but
when i dont have a proper date value, i want to insert NULL in database column. However EF is saving column with Empty string
I tried to change the StoreGeneratedPattern for the field to "Identity" but problem with it is, I cant assign value to DTCLose field.
How can i have both the things?
1. EF should insert NULL in database when proper value is not there
2. proper value otherwise
Please help
Thanks
Anup
This is wrong System.DBNull.Value.ToString() because at the end you will have string object, ToString() never returns null.
You have to set DTCLOSE = null
Also, with EF you don't have to use DBNull, you just define nullable property and set it null
You Can use this :
Nullable<DateTime> date=null;
var entity = new Model()
{
GoDate = date
};
DataContext.Models.Add(entity);
DataContext.SaveChanges();

EntLib Way to Bind "Null" Value to Parameter

I wish to pass Null Value to the parameter as follow:
_db.AddInParameter(dbCommand, "Id", DBNull.Value, myContactPerson.Id);
I am receiving the following error :
"can not convert "System.DBNull to System.Data.DbType".
I know the meaning of this error.
But i need to supply null value to myContactPerson.Id
How can i achieve this ?
If myContactPerson.Id isn't an auto-number, then why not just pass 0.
DBType should be passed in that parameter and should match your the dbtype (string, int, etc.) for the table that you are comparing with in your database. You would replace your value field "myContactPerson.Id" with DBNull.Value to always pass the null value.