I stumbled across this thing today:
I have a little helper method with the following:
private static T GetValOrDefault<T>(this IDataRecord rdr, string name)
{
return rdr[name] is T ? (T) rdr[name] : default(T);
}
and all my models use public long Id { get; set; }
SQL server columns are BIGINT
Somehow the GetValOrDefault<long>("Id") returns '0', and i went ahead and used the Immediate Window there, and had a look at rdr["Id"].GetType()
It was Int32... any ideas why that happens?
Everywhere i look, it says BIGINT = INT64 = long... and somehow the SqlDataReader gives me int32...
Edit:
That is my Sql Query:
SELECT
Id,
Created,
CreatedById,
LastModified,
LastModifiedById,
Deleted,
DeletedById
FROM dbo.MyTable
WHERE Id = @id