我想现在我知道问题出在哪里,但我不知道我会解决这个问题。
实际上我正在通过 entityFramework 4.1 获取数据,并且由于我的搜索条件是动态的,所以我只有一种方法可以做到这一点,enter code here
这就是现在
using System;
using System.Linq;
using System.Data.Entity;
using QTrac.Models;
using System.Transactions;
namespace QTrac.DAL
{
public class AssetManagementSearchRepository : RepositoryBase<AssetManagementSearch>, IAssetManagementSearchRepository
{
public AssetManagementSearchRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { }
#region IAssetManagementSearchResponseRepository Members
public IQueryable<AssetManagementSearch> GetSearchResult(SearchRequest request)
{
IQueryable<AssetManagementSearch> query = DbSet;
using (var context = new QTracContext()) {
using (var tx = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted })) {
//try {
if (!String.IsNullOrEmpty(request.FileCode)) {
query = query.Where(d => d.FileCode.StartsWith(request.FileCode));
}
if (!String.IsNullOrEmpty(request.SerialNo)) {
query = query.Where(d => d.SerialNo.StartsWith(request.SerialNo));
}
if (!String.IsNullOrEmpty(request.TopLevelEquipment)) {
query = query.Where(d => d.ParentToolSet.StartsWith(request.TopLevelEquipment));
}
if (!String.IsNullOrEmpty(request.EquipmentState)) {
query = query.Where(d => d.EqpState.StartsWith(request.EquipmentState));
}
if (!String.IsNullOrEmpty(request.EquipmentStatus)) {
query = query.Where(d => d.EqpStatus.StartsWith(request.EquipmentStatus));
}
if (!String.IsNullOrEmpty(request.DFP)) {
query = query.Where(d => d.DFP.StartsWith(request.DFP));
}
if (request.Active.HasValue) {
query = query.Where(d => d.IsActive == request.Active);
}
if (!String.IsNullOrEmpty(request.OwnerSite)) {
query = query.Where(d => d.OwnerSite.StartsWith(request.OwnerSite));
}
if (!String.IsNullOrEmpty(request.ControlSite)) {
query = query.Where(d => d.ControlSite.StartsWith(request.ControlSite));
}
if (!String.IsNullOrEmpty(request.Location)) {
query = query.Where(d => d.Location.StartsWith(request.Location));
}
if (!String.IsNullOrEmpty(request.StampedFC)) {
query = query.Where(d => d.STAMPEDFC.StartsWith(request.StampedFC));
}
if (!String.IsNullOrEmpty(request.StampedSN)) {
query = query.Where(d => d.STAMPEDSN.StartsWith(request.StampedSN));
}
if (!String.IsNullOrEmpty(request.CustomsStatus)) {
query = query.Where(d => d.CustomsStatus.StartsWith(request.CustomsStatus));
}
if (!String.IsNullOrEmpty(request.ImportType)) {
query = query.Where(d => d.ImportType.StartsWith(request.ImportType));
}
if (!String.IsNullOrEmpty(request.ClientBasket)) {
query = query.Where(d => request.ClientBasket.Contains(d.ClientBasket));
}
if (!String.IsNullOrEmpty(request.ImportClient)) {
query = query.Where(d => request.ImportClient.Contains(d.ImportClient));
}
if (!String.IsNullOrEmpty(request.AssignedClient)) {
query = query.Where(d => d.AssignedClient.StartsWith(request.AssignedClient));
}
if (!String.IsNullOrEmpty(request.FileCodesByToolFamily)) {
query = query.Where(d => request.FileCodesByToolFamily.Contains(d.FileCode));
}
return query.AsNoTracking();
//}
//catch(Exception e) {
// throw e.InnerException;
//}
//finally {
// //Context.Dispose();
//}
}
}
}
#endregion
}
}
通常它工作正常,一种情况是当我从源代码管理下载我的代码时它不起作用,第二种情况是昨天我正在使用相同的解决方案但不同的页面我在 .edmx 文件中添加了许多视图和存储过程,当我测试这个搜索屏幕时它不起作用,每次都返回 500 错误,我从 mvc telerik 网格错误事件中捕获了 500 错误。
如果我将此代码更改为没有动态
return Get(filter: p => p.ACTIVE == active, orderBy: o => o.OrderBy(p => p.NAME), tracking: false);
然后搜索开始工作。
请告诉我这个问题。谢谢