I got this error in my code. How should I clear this?

96 Views Asked by At

This is my code:

public MyResponse InsertTeam(MyRow Row) 
{ 
    try 
    { 
        var connection = SqlConnections.NewByKey("Cred"); 

        /* Getting Insert to LogBook table */
        TeamRow team = new TeamRow();
        team.TeamId = TeamRow.Fields.TeamId;
        
        var teamId = User.GetIdentifier();
        
        team.CreatedBy = User.GetIdentifier();
        team.CreatedOn = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"));
    }
    catch 
    { }

    return new SaveResponse();
}

I get this error when running it:

Cannot implicitly convert type 'Serenity.Data.Int32Field' to 'int?'.

on this line:

team.TeamId = TeamRow.Fields.TeamId;

How should I clear this?

1

There are 1 best solutions below

3
Sabur Islam On

I think you are directly trying to assign the "Serenity.Data.Int32Field" to a nullable (int?) integer.... if you want so you can explicitly convert the "TeamRow.Fields.TeamId" part to a nullable int? using the value.

team.TeamId = (TeamRow.Fields.TeamId == null)
              ? null 
              : TeamRow.Fields.TeamId.Value;

or you should check the docs for the Serenity framework, if they provide any explicit method to do so.