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

Already on GitHub? Sign in to your account

PersistenceSpecification not working with Compenents mapped #187

Open
alexjamesbrown opened this Issue Nov 1, 2012 · 11 comments

Comments

Projects
None yet
4 participants

I've got the following PersistenceSpecification:

new PersistenceSpecification<MyClass>(session)
        .CheckProperty(c => c.Name, "Testing")
        .CheckProperty(c => c.Address.Address1, "Address 1")
        .CheckProperty(c => c.Address.Address2, "Address 2")
        .CheckProperty(c => c.Address.Address3, "Address 3")
        .VerifyTheMappings();

When this is run, the .CheckProperty(c => c.Address.Address1, "Address 1") throws an error.

Upon looking in my database, I see the Name column has been set (to "Testing") however the columns mapped to the component are not

I've mapped the Address component like this (In MyClassMap)

  Component(x => x.Address, m =>
  {
    m.Map(x => x.Address1);
    m.Map(x => x.Address2);
    m.Map(x => x.Address3);
  });

As it turns out, this is because my Address was null

Adding this to the ctor of MyClass fixed this:

  Address = new Address();

But...

Shouldn't PersistenceSpecification of thrown an exception?

If I tried to manually create it like this:

var myClass = new MyClass();
myClass.Address.Address1 = "Something";

Then I get an exception...

Something not right somewhere?

Collaborator

chester89 commented Nov 1, 2012

What kind of exception? May be you can post a stacktrace? I'm not quite following, I'm sorry

Sorry..
When I say 'then i get an exception'
I mean that I (quite rightly) get object not set to an instance of an object....

But that's in 'my' code - not using PersistenceSpecification

Collaborator

chester89 commented Nov 1, 2012

I'm not sure that Persistence Specification can figure out that you're using a component. May be there are some specific way to tell it about that, like CheckReference method that verifies that you have a n-to-one relationship?

Collaborator

chester89 commented Nov 1, 2012

I'm having a look at the code - it seems strange that CheckComponentList exists, but CheckComponent doesn't :(

Yeah.. that's what I thought...

There should be a way of testing this mapping though I think?

Collaborator

chester89 commented Nov 2, 2012

I'm thinking that writing your own extension method like CheckReference is a way to go.

The correct way to test this would be to instantiate your own instance of the class you want to persist, then use the overload of PersistenceSpecification.VerifyTheMappings that takes an instance of the class.

@hotgazpacho perfect, thanks
I think the wiki page should be updated to show that....?

Owner

jagregory commented Nov 6, 2012

That sounds like a good idea Alex.

On Wed, Nov 7, 2012 at 12:28 AM, Alex Brown notifications@github.comwrote:

@hotgazpacho https://github.com/hotgazpacho perfect, thanks
I think the wiki page should be updated to show that....?


Reply to this email directly or view it on GitHubhttps://github.com/jagregory/fluent-nhibernate/issues/187#issuecomment-10110390.

James Gregory

Tel: +61 (0) 411 619 513
Website: http://jagregory.com
Twitter: @jagregory http://twitter.com/jagregory

Collaborator

chester89 commented Feb 14, 2013

How did you solve this? Extension method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment