我想现在我知道问题出在哪里,但我不知道我会解决这个问题。
实际上我是通过entityFramework 4.1获取数据,因为我的搜索条件是动态的,所以我只有一种方法可以做到这一点,我现在{k} 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);
然后搜索开始工作。
请告诉我这个问题。 感谢