Getting colmumn mapping exception

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?

Thanks

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.

Hello mythz,
no this won’t happen as well even if I specify the columns or if I get data from stored procedure

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

If it can’t find an exact match OrmLite will fallback and try match find the best matching column, you can disable this behavior with:

OrmLiteConfig.DisableColumnGuessFallback = false;

For my main problem consider this table

CREATE TABLE [dbo].[SOME_TABLE](
[ID] [int] NOT NULL,
[Exist] [int] NULL,
CONSTRAINT [PK_SOME_TABLE] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

with the DisableColumnGuessFallback =false

if the column is not mapping the alias I got a silent exception

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.

Yes,
do you think it’s possible in future release to have an event that tell’s the specified column is not found? just for logging purpose?

Thanks

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