我的网站上有一个搜索功能,有时会失败。它在 C# / ASP.NET / WebForms 中构建并使用 ActiveRecord。
基本上,当我从我的数据库中的 VIEW 返回太多记录时,我会收到 en UPDATE 错误。
string query = "s";
Order[] orders = new order[] { Order.Asc("LastName") };
List<ICriterion> crit = new List<ICriterion>();
Crit.Add(Expression.Sql(String.Format("LastName" LIKE '%{0}%' OR FirstName LIKE '%{0}%'", query)));
var rv = ActiveRecordBase.FindAll(typeof(vMyView), orders, crit.ToArray())
当使用“s”作为查询进行搜索时,我的代码的上述部分在 FindAll 命令上失败(我会得到很多结果)。但是使用“x”作为查询它就像一个魅力。
我得到的错误是:
View or function 'vAllowedVessels' is not updatable because the modification affects multiple base tables.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: View or function 'vAllowedVessels' is not updatable because the modification affects multiple base tables.
Source Error:
Line 74: List<ICriterion> crit = new List<ICriterion>();
Line 75: Crit.Add(Expression.Sql(String.Format("LastName" LIKE '%{0}%' OR FirstName LIKE '%{0}%'", query)));
Line 75: var rv = ActiveRecordBase.FindAll(typeof(vMyView), orders, crit.ToArray()) <--- This is highlighted in red!
Stack Trace:
[GenericADOException: could not update: [Ovf.Model.vAllowedVessels#3843][SQL: UPDATE vAllowedVessels SET FixtureId = ?, ContractDate = ?, No = ?, ContractForm = ?, VesselName = ?, Status = ?, CreatedDate = ?, Buyer = ?, BuyerName = ?, BuyerShortName = ?, BuyPrincipal = ?, BuyPrincipalName = ?, Seller = ?, SellerName = ?, SelPrincipal = ?, SelPrincipalName = ?, Operator = ?, Broker = ?, UsrCode = ? WHERE VesselFolderId = ?]]
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +2474
NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +335
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) +1898
NHibernate.Action.EntityUpdateAction.Execute() +764
NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +48
NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +128
NHibernate.Engine.ActionQueue.ExecuteActions() +50
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +215
NHibernate.Event.Default.DefaultAutoFlushEventListener.OnAutoFlush(AutoFlushEvent event) +225
NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet`1 querySpaces) +288
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +524
NHibernate.Impl.CriteriaImpl.List(IList results) +76
NHibernate.Impl.CriteriaImpl.List() +71
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order[] orders, ICriterion[] criteria) in c:\TeamCity\buildAgent\work\e41ee5ead2eba140\src\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:1034
[ActiveRecordException: Could not perform FindAll for vAllowedVessels]
Castle.ActiveRecord.ActiveRecordBase.FindAll(Type targetType, Order[] orders, ICriterion[] criteria) in c:\TeamCity\buildAgent\work\e41ee5ead2eba140\src\Castle.ActiveRecord\Framework\ActiveRecordBase.cs:1046
Ovf.Model.vAllowedVessels.SearchByType(String query, String typename, String usrCode) in g:\Dev\2012\OnTrack\model\Profile\vAllowedVessels.cs:76
Search_Default.BindVesselFolders() in g:\Dev\2012\OnTrack\webapp\Search\Default.aspx.cs:155
Search_Default.ChangeStatus(Object sender, EventArgs e) in g:\Dev\2012\OnTrack\webapp\Search\Default.aspx.cs:145
System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e) +116
System.Web.UI.WebControls.DropDownList.RaisePostDataChangedEvent() +133
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent() +13
System.Web.UI.Page.RaiseChangedEvents() +132
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1644
应该注意的是,我不想更新任何东西 - 只需查询我的 VIEW。