Hello,
I’ve noticed a behavior I don’t like a lot, I had a poco mapping a table and I miswrote the alias. I was expecting to see in my log an entry but it doesnt’ happen…
Consider this example
void Main()
{
var dbFactory = new OrmLiteConnectionFactory(@"something", SqlServerDialect.Provider);
using (var db = dbFactory.Open())
{
var query = db.SqlList<Contratto>("SELECT TOP 10 * FROM SOME_TABLE");
query.Dump();
db.GetLastSql().Dump();
}
}
class Contratto
{
[Alias("ID")]
public int Id { get; set; }
[Alias("NotExists")]
public int NotExists { get; set; }
}
If I’ve the exception thrown enabled I got the exception that it doesn’t find NotExists column but it values it at its default (It can be ok since it won’t break the result)
Is there a way (maybe in ormlite config) to catch that kind of error?
It’s hard to tell the exact issue from the code sample without knowing what the schema of SOME_TABLE is, but from your description it sounds like you want OrmLite to catch spelling mistakes. OrmLite by design maps to columns it can match, it doesn’t force matching every field, so you could have a POCO that only populates a subset of the result set.
Since you’re using a Custom SQL with a wildcard SELECT * it’s not going to generate a invalid query with the incorrectly spelt aliases, but if instead you used a typed query, e.g:
var q = db.From<Contratto>().Take(10);
It would select each columns individually and would have thrown an error when selecting an invalid column.
Demis,
I’ve noticed a problem with Alias attribute… I’ve tested in with .40 don’t know if this apply to other version…
consider this alias
[Alias("NotExists")]
public int NotExists { get; set; }
If I’ve got a column called DONotExists it fills the values of this column instead of setting to null… it seems to do an EndWith id I call on db DONotExists_ it doesn’t (correctly) fill the property
This problem is not related to the problem I’ve posted in the thread just an update
By Silent exception do you mean no error? Cause that’s what’s meant to happen, it only maps what it can and if you disable the fallback inference it wont attempt to coerce to a potential matching column.
I prefer not to pollute the logs for normal operations as OrmLite’s designed to make it easy to map to any POCO’s, i.e. they can partially populate a POCO subset. You can add a feature request to see if this is something others want as well: http://servicestack.uservoice.com/forums/176786-feature-requests