Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# linq to实体无法将int转换为字符串_C#_Asp.net Mvc_Linq_Entity Framework - Fatal编程技术网

C# linq to实体无法将int转换为字符串

C# linq to实体无法将int转换为字符串,c#,asp.net-mvc,linq,entity-framework,C#,Asp.net Mvc,Linq,Entity Framework,我尝试过滤返回剑道组合框的数据,过滤基于ID, 我需要返回包含过滤文本的所有记录,而不仅仅是等于1的记录,所以我所做的是将ID转换为字符串,如下所示 Items = Mapper.Map<List<PurchaseOrder>, List<PurchaseOrderViewModel>>( purchaseOrderRepository.GetMany(x =>

我尝试过滤返回剑道组合框的数据,过滤基于ID, 我需要返回包含过滤文本的所有记录,而不仅仅是等于1的记录,所以我所做的是将ID转换为字符串,如下所示

Items = Mapper.Map<List<PurchaseOrder>, List<PurchaseOrderViewModel>>(
                purchaseOrderRepository.GetMany(x => 
                                                x.PurchaseOrderID
                                                 .ToString()
                                                 .Contains(text))
                                                 .ToList());
Items=Mapper.Map(
purchaseOrderRepository.GetMany(x=>
x、 PurchaseOrderID
.ToString()
.包含(文本))
.ToList());
但它总是回来 linq to entities无法识别方法'system.string tostring()'

因此,我尝试将dbset转换为where语句之前的list,正如我在另一篇文章中发现的那样 但是我得到了另一个错误,即该列表不包含Where的定义(dbSet是IDbSet的一个实例)

公共虚拟IList GetMany(表达式,其中)
{
返回dbset.ToList().Where(Where.ToList();
}
这是我最初(当前)的get方法

sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data;
using System.Linq.Expressions;
using Spine.ERP.DataAccess.DbFirstDataAccess;
using Spine.ERP.DataModel.Helpers;
namespace Spine.ERP.DataAccess.Infrastructure
{
    public abstract class RepositoryBase<T> where T : class
    {

        private SSSDBEntities dataContext;

        private readonly IDbSet<T> dbset;

        protected RepositoryBase(IDatabaseFactory databaseFactory)
        {
            DatabaseFactory = databaseFactory;
            dbset = DataContext.Set<T>();
        }

       protected IDatabaseFactory DatabaseFactory
        {
            get;
            private set;
        }


        protected SSSDBEntities DataContext
        {
            get { return dataContext ?? (dataContext = DatabaseFactory.Get()); }
        }
    public virtual IQueryable<T> GetMany(Expression<Func<T, bool>> where)
        {
            return dbset.Where(where);
        }
  }
}
sing系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Data.Entity;
使用系统数据;
使用System.Linq.Expressions;
使用Spine.ERP.DataAccess.DbFirstDataAccess;
使用Spine.ERP.DataModel.Helpers;
命名空间Spine.ERP.DataAccess.Infrastructure
{
公共抽象类RepositoryBase,其中T:class
{
私有SSSDbenties数据上下文;
专用只读IDbSet数据库集;
受保护的RepositoryBase(IDatabaseFactory databaseFactory)
{
DatabaseFactory=DatabaseFactory;
dbset=DataContext.Set();
}
受保护的IDatabaseFactory数据库工厂
{
得到;
私人设置;
}
受保护的SSSDbenties数据上下文
{
获取{return dataContext???(dataContext=DatabaseFactory.get());}
}
公共虚拟IQueryable GetMany(表达式,其中)
{
返回dbset.Where(Where);
}
}
}
我还能做些什么来解决这个问题呢?

有一个类包含许多SQL函数,可用于LINQ。试试看
SqlFunctions.StringConvert

Items = Mapper.Map<List<PurchaseOrder>, List<PurchaseOrderViewModel>>(
                purchaseOrderRepository
                   .GetMany(x => SqlFunctions
                                  .StringConvert((double?) x.PurchaseOrderID)
                                  .Contains(text))
                                  .ToList());

谢谢你的回复,但我以前尝试过这个解决方案,但同样的错误返回状态,它应该可以工作。我从来没有遇到过这样的问题。我看不出为什么在这段代码中会出现同样的错误。您是否正在调用
ToString()
不,我没有在任何地方调用ToString(),我无法理解您为什么会遇到完全相同的错误。至少应该有所不同。(我已经编辑了上面的代码:不是将演员列表改为双精度?而不是双精度;也许这就是问题所在)谢谢你的帮助,但它仍然会引发相同的错误,也许它应该先转换为列表,然后再进行筛选,但我不能这样做,因为它总是返回where not found
Items = Mapper.Map<List<PurchaseOrder>, List<PurchaseOrderViewModel>>(
                purchaseOrderRepository
                   .GetMany(x => SqlFunctions
                                  .StringConvert((double?) x.PurchaseOrderID)
                                  .Contains(text))
                                  .ToList());
purchaseOrderRepository.Set<PurchaseOrder>()
   .Where(x => SqlFunctions
       .StringConvert((double?) x.PurchaseOrderID)
       .Contains(text))