This line gives me this error:
if (db.T_TarefaParceiro.Max(p => p.IDTarefaParceiro) != null)
The error
The cast to value type 'System.Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
Because the PathTerminal field is a primary key, it can not be nullable. How do I resolve this?