开发者

How to save a single entity or entities within an NHibernate Session without saving other dirty entities?

How do I flush certain parts of a session but not other parts?

For example:

ISessionFactory sessionFactory = CreateSessionFactory();
ISession session = sessionFactory.OpenSession();
Employee first = session.Get<Employee>(FirstEmployeeId);
Employee second = session.Get<Employee>(SecondEmployeeId);
first.Name = "Michael Johnson";
second.Name = "Karl Johnson";
session.Flush(first);

Sends to the database:

Update Employee SET FirstName = 'Michael Johnson' where Id = 123;

This would basically save the first Employee to the database but not the second.

The scenario I'm trying to support is when you have a tabbed WPF application with two employees open at once and editing both.

I cannot support two sessions because, let's say, they inter开发者_Go百科act so much that I would risk having stale data if I made changes in one (for example, Employees have ReportsTo : Employee which renders as a Name. First reports to Second. If I change the name on Second, I should see this in the tab for First.


session.Evict(second)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜