简体   繁体   中英

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?

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.

Apart from that you can work with proxies, simply use session.Load(...) to load a proxy object for the given id. This will not hit the database. But you can use the proxy to session.Delete the object.

See more details here: http://nhibernate.info/blog/2009/04/29/nhibernate-the-difference-between-get-load-and-querying-by-id.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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