Hi,
You mean, it should test for null and if so, it should pick a default value or something? As there's not much to do with a null if the target can't hold it. I.e.: the variable is of type int and the parameter returns null.... If a parameter can return null, it should be marked as such in the designer so the variable is generated as a nullable type, if it's a value type.
Yes, the generated code for LLBLGen has a small difference
public static int SgGetPartajbranskomhplkodu(System.Int32 partajbransno, ref System.String partajkomhplkodu, ref System.String partajkomalacakhplkodu, ref System.Int32 returnValue, DataAccessAdapter adapter)
{
// create parameters. Add 1 to make room for the return value parameter.
SqlParameter[] parameters = new SqlParameter[3 + 1];
parameters[0] = new SqlParameter("@PARTAJBRANSNO", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "", DataRowVersion.Current, partajbransno);
parameters[1] = new SqlParameter("@PARTAJKOMHPLKODU", SqlDbType.VarChar, 20, ParameterDirection.InputOutput, true, 0, 0, "", DataRowVersion.Current, partajkomhplkodu);
parameters[2] = new SqlParameter("@PARTAJKOMALACAKHPLKODU", SqlDbType.VarChar, 20, ParameterDirection.InputOutput, true, 0, 0, "", DataRowVersion.Current, partajkomalacakhplkodu);
parameters[3] = new SqlParameter("RETURNVALUE", SqlDbType.Int, 0, ParameterDirection.ReturnValue, true, 10, 0, "", DataRowVersion.Current, returnValue);
int toReturn = adapter.CallActionStoredProcedure("[ELWIN2].[dbo].[SG_GET_PARTAJBRANSKOMHPLKODU]", parameters);
if(parameters[1].Value!=System.DBNull.Value)
{
partajkomhplkodu = (System.String)parameters[1].Value;
}
if(parameters[2].Value!=System.DBNull.Value)
{
partajkomalacakhplkodu = (System.String)parameters[2].Value;
}
returnValue = (int)parameters[3].Value;
return toReturn;
}
It checks the field for DBNull. The code fragment has generated by v 2.6 but i don't think it's changed in v4.1. Also i tried to use IsOptional field setting in designer but it did't make any difference.
Are you sure EF6 opens the connection as soon as you create a context object? I have not read about that. To my knowledge they open a connection when they need to, i.e. when you execute a query or when you save the changes. It then closes the connection afterwards. To my knowledge: http://msdn.microsoft.com/en-us/data/dn456849 says what our code does, or am I misinterpreting it? (could be, their connection management is a moving target sometimes).
I'm using the same document as a reference and my implementation exactly fits
Database.Connection.Open() / Behavior in EF6 and future versions paragraph.
Opening connection explicitly and calling stored procedures and SaveChanges repeatedly.