Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore() is ignored by FluentMapping #59

Closed
CaspianCanuck opened this issue Dec 3, 2013 · 5 comments
Closed

Ignore() is ignored by FluentMapping #59

CaspianCanuck opened this issue Dec 3, 2013 · 5 comments

Comments

@CaspianCanuck
Copy link
Contributor

It looks like columns that are configured using the FluentMapping API to be ignored are included in the generated INSERT statement.

I have this class:

public class InvoiceHeader
{
    // A bunch of regular properties that are persisted ...

    // A child object property that should be ignored
    public virtual InvoiceAdditionalData AdditionalData { get; set; }

    // A child collection property that should be ignored
    public virtual ICollection<InvoiceLineItem> LineItems { get; set; }
}

In my FluentMapping configuration I do this:

FluentMappingConfiguration.Scan(scanner =>
{
    scanner.Assembly(typeof(IDocumentDatabase).Assembly);
    scanner.IncludeTypes(x => x.Namespace.StartsWith(typeof(InvoiceHeader).Namespace));
    scanner.Columns.IgnoreComplex();
    scanner.OverrideMappingsWith(new InvoiceHeaderMap());
}

I have confirmed by putting a breakpoint inside the IgnoreComplex lambda that it returns true for both AdditionalData and LineItems (i.e. they should be ignored).

However, the generated INSERT statement still contains both of these properties as if they were columns.

This also happens even if I explicitly Ignore() these properties in my InvoiceHeaderMap class.

@CaspianCanuck
Copy link
Contributor Author

Looking deeper in the NPoco code I can see that it has something to do with TypeDefinition.ExplicitColumns being set to true in FluentMappingConfiguration.CreateMappings().

Then in the FluentMappingsPocoData constructor the code skips checking a property's IgnoreColumn flag is the ExplicitColumns is true.

I am having a hard time figuring out the logic behind this. As far as I am concerned, if a column is flagged as ignored then it should be truly ignored when SQL is built.

@CaspianCanuck
Copy link
Contributor Author

I got it! I need to pass false into the second optional parameter of Columns() in my InvoiceHeaderMap's constructor.

Adam, you might wanna clarify this fine point in your wiki to help other devs avoid a similar confusion.

@schotime
Copy link
Owner

schotime commented Dec 3, 2013

Hey,
I'm trying to digest all of this.
Let me have a look and I'll get back to you. Could you summarize what you have found and what you think could be changed etc, so we have a plan of attach so to speak.
Cheers,
Adam

@schotime schotime reopened this Dec 3, 2013
@CaspianCanuck
Copy link
Contributor Author

No need to change anything in the code itself, perhaps just make a point of explaining the importance of the explicitColumns argument in the wiki. Currently it's not even mentioned anywhere in your wiki example, so it's easy to overlook.

Thanks for your quick response!

@schotime
Copy link
Owner

schotime commented Dec 5, 2013

2.2.45 has fixed the Ignore. It was not working when using the FluentMappings. It will always look at the ignore now.
Thanks!

@schotime schotime closed this as completed Dec 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants