1

I do a query through nhibernate to get a record back from the database.

var result  = session.Query<TableA>().Where(x => x.Id == 10).FirstOrDefault();
result.Where = "hi";
session.Update(result)
session.Commit();

So I get a result back and update a property and try to update and then commit it. This will crash because I have forigen key to Table B(Table A can Has one Table B and Table B has many Table A's)

So this reference cannot be null. So when it tries to do an update it crashes.

So I have to do

       var result  = session.Query<TableA>().Where(x => x.Id == 10).FirstOrDefault();
        result.Where = "hi";
        result.TableB = session.Load<TableB>(1);
        session.Update(result)
    session.Commit();

Then it is happy.

How can I do an update without having to load TableB in?

1 Answer 1

1

Set the Update value of the TableB property mapping to false. I'm not sure how you'd do this using Fluent NHibernate, but it looks like the SetAttribute method will do this for you.

Something along the lines of: .SetAttribute("update", "false");

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.