开发者

Why does this NHibernate Linq query attempt to execute an insert statement?

I am encountering a very strange issue I wonder if anyone has seen before. I have as part of my Save() method in a repository that it will search out and find each associated tag by it's name. There is a line in 开发者_如何转开发there that looks like this.

var tagRepo = (from t in tagRepository.Query() where t.Name == tag.Name select t).SingleOrDefault();

As soon as that line executes it throws this exceptions

GenericADOException: could not insert: [Core.Domain.Model.Tag][SQL: INSERT INTO [Tag] (Name) VALUES (?); select SCOPE_IDENTITY()]]

As far as I can tell or understand about what is happening here the Linq query shouldn't be executing an insert statement. Any ideas?

Thanks.


I just fixed it so I thought I would share the answer. The query in question was inside of another session. So there were these lines

using (var session = GetSession())
using (var transaction = session.BeginTransaction())

Creating a session and a new transaction. After that the call the .Query() was actualy doing this.

return GetSession().Linq<T>().AsQueryable();

So it was trying to get another session inside my existing session and transaction. I moved the query and updates above the GetSession() and BeginTransaction() and everything worked properly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜