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

PersistenceSpecification not working with Compenents mapped #187

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

PersistenceSpecification not working with Compenents mapped #187

alexjamesbrown opened this issue Nov 1, 2012 · 11 comments

Comments

@alexjamesbrown
Copy link

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);
  });
@alexjamesbrown
Copy link
Author

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?

@chester89
Copy link
Collaborator

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

@alexjamesbrown
Copy link
Author

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

@chester89
Copy link
Collaborator

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?

@chester89
Copy link
Collaborator

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

@alexjamesbrown
Copy link
Author

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

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

@chester89
Copy link
Collaborator

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

@hotgazpacho
Copy link

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.

@alexjamesbrown
Copy link
Author

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

@jagregory
Copy link
Collaborator

That sounds like a good idea Alex.

On Wed, Nov 7, 2012 at 12:28 AM, Alex Brown [email protected]:

@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//issues/187#issuecomment-10110390.

James Gregory

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

@chester89
Copy link
Collaborator

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
Projects
None yet
Development

No branches or pull requests

4 participants