Dapper can't ignore nested objects for parameter?

dapper dapper-extensions

Question

I am beginning to use Dapper and love it so far. However as i venture further into complexity, i have ran into a big issue with it. The fact that you can pass an entire custom object as a parameter is great. However, when i add another custom object a a property, it no longer works as it tries to map the object as a SQL parameter. Is there any way to have it ignore custom objects that are properties of the main object being passed thru? Example below

public class CarMaker
{
public string Name { get; set; }
public Car Mycar { get; set; }
}

propery Name maps fine but property MyCar fails because it is a custom object. I will have to restructure my entire project if Dapper can't handle this which...well blows haha

Popular Answer

Dapper extensions has a way to create custom maps, which allows you to ignore properties:

public class MyModelMapper : ClassMapper<MyModel>
{
    public MyModelMapper()
    {
        //use a custom schema
        Schema("not_dbo_schema"); 

        //have a custom primary key
        Map(x => x.ThePrimaryKey).Key(KeyType.Assigned);

        //Use a different name property from database column
        Map(x=> x.Foo).Column("Bar");

        //Ignore this property entirely
        Map(x=> x.SecretDataMan).Ignore();

        //optional, map all other columns
        AutoMap();
    }
}

Here is a link



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why