henkmollema / Dommel

CRUD operations with Dapper made simple.
MIT License
634 stars 100 forks source link

Ignore on Property mappings do not works #13

Closed rafakwolf closed 9 years ago

rafakwolf commented 9 years ago

When i'm trying to make a Crud with this classes and ignore property Friends on Person class mapping, the "ignore" don't works with Dommel.

Error on insert method: "System.NotSupportedException: The member Friends of type Friend cannot be used as a parameter value".

public class Person{

  public int ID {get;set;}
  public string Name {get;set;}

  public List<Friend> Friends {get;set;}
}

public class Friend{
  public int ID {get;set;}
  public string Name {get;set;} 
}

Thanks in advance

henkmollema commented 9 years ago

That exception is thrown by Dapper. It tries to map the Friends property to a sql parameter, which is not supported since it's a complex type.

rafakwolf commented 9 years ago

OK, but how can i ignore complex types on Insert and Update extension methods from Dommel ?

I made a pull request, please take a look.

Thanks alot!

henkmollema commented 9 years ago

This has nothing to do with Dommel. Dapper will try to map the complex type to a sql parameter, whether it exists in the sql query or not. Changing this on the side of Dommel won't fix your issue. I guess your best option is to create a dedicated class for update/insert with Dommel and Dapper.

rafakwolf commented 9 years ago

With all respect i disagree. OK, but for what Dommel Mapping exists then ? If is capable to set the KeyField, then must be capable to set the Ignore fields to, isn't ?

Thanks alot

henkmollema commented 9 years ago

I guess you used Dapper.FluentMap.Dommel. This utility provides a mapping from database column names back to C# POCO properties when the result from the query is received. It's also used when Dommel builds SQL queries to map the POCO properties to column names. The Ignore method is only used when mapping query results back to POCO's, not when building sql queries.

rafakwolf commented 9 years ago

But the column names are used for build queries, isn't ?

henkmollema commented 9 years ago

Correct, perhaps it should also be used for that. But that won't fix your issue, since it occurs when Dapper is trying to map it to a database type. See: https://github.com/StackExchange/dapper-dot-net/blob/master/Dapper%20NET40/SqlMapper.cs#L910

rafakwolf commented 9 years ago

I understand... but when i invoke Connection.Insert()... a query will be constructed correct ? This construction must have ( Not complex types and Not Ignored properties ).

Sorry for the insistence.

Ps.: Did you see my pull request ?

henkmollema commented 9 years ago

I think you're right, I'll have to look further into it.

rafakwolf commented 9 years ago

This library is awesome, i would like to continue contributing