I'm implementing some generic solution to query IDs from database. All I know, is for example that given a table A, it has a column Id having an integer type. I don't know if it's uint32 or int64, etc.
I'd like to query the maximum of the ID using DbContext.Database.SqlQuery, however, I cannot make it work in a weakly typed manner. So I always have to provide a strong element type, which basically I wouldn't like as it might be int or long.
If I'm running it like .SqlQuery<object>, than I'm getting exception when trying to convert it to for example long using Convert.ToInt64, saying that System.Object is not convertible to that type. Seems like EF is kind of misunderstanding me or so.
Even when the actual underlying type is Int32, and I try to query for long, I get an exeption stating that I cannot convert Int32 to long, which completely does not make sense to me.
How could I achieve a weakly typed query result which I can just convert to whatever I want?