简体   繁体   English

流利的NHibernate查询,无需加载

[英]Fluent-NHibernate Querying without loading

i'm trying to do a fast update query without loading the updated value i tried to use this code 我正在尝试执行快速更新查询而不加载更新后的值,我试图使用此代码

 public void Save(int PlayerID, string Column, object Value)
        {
            using (ISession session = new SessionManager(_connectionString).Open())
            {
                IQuery query = session.CreateQuery("UPDATE Players SET " + Column + "= :newValue WHERE PlayerID=:PlayerID");
                query.SetParameter("newValue", Column);
                query.SetParameter("PlayerID", PlayerID);
                query.ExecuteUpdate();
            }
        }

but i get error Player is not mapped while its actually mapped and i already using it in another statements. 但是我收到错误消息,而实际上未映射播放器,并且我已经在另一条语句中使用它了。

I guess your entity name is Player and not Player s right? 我猜你的实体名称是Player ,而不是球员权利?

IQuery query = session.CreateQuery("UPDATE Player SET " + Column + "= :newValue WHERE PlayerID=:PlayerID");
            query.SetParameter("newValue", Column);
            query.SetParameter("PlayerID", PlayerID);
            query.ExecuteUpdate();

you don't have to specify the name of the table in hql, just the name of the entity. 您不必在hql中指定表的名称,只需指定实体的名称。

Apart from that you can work with proxies, simply use session.Load(...) to load a proxy object for the given id. 除此之外,您还可以使用代理,只需使用session.Load(...)为给定的ID加载代理对象。 This will not hit the database. 这不会打到数据库。 But you can use the proxy to session.Delete the object. 但是您可以使用代理进行session.Deletesession.Delete对象。

See more details here: http://nhibernate.info/blog/2009/04/29/nhibernate-the-difference-between-get-load-and-querying-by-id.html 在此处查看更多详细信息: http : //nhibernate.info/blog/2009/04/29/nhibernate-the-difference-between-get-load-and-querying-by-id.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM