如何将int转换为字符串 [英] How to convert a int to string

查看:57
本文介绍了如何将int转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个查询,我试图看看它们是否是值的一部分































br> {
a.PermitID,
a.PermitNumber
};

entrys = entrys.Where(a1 => a1.PermitNumber.Value.ToString()。包含(模式.PermitNumber.ToString()));

给我错误,
LINQ to Entities无法识别方法'System.String ToString()'方法,并且此方法无法转换为存储表达式。

我读过其他帖子说:
hat error意味着LINQ to Entities没有
知道如何为该方法调用生成SQL 。您可以首先实现
查询(调用ToList(),ToArray(),First()或其他导致查询执行的
),因此数据在内存中,并且
然后再进行连接。或者使用
AsEnumerable()

但是我不太确定如何使用我的查询。

谢谢
< br>

解决方案

好的我弄明白了。我把它转换为AsEnumerable然后做了我的检查,然后把它转换回AsQueryable。

var entrys1 =来自in entrys.AsEnumerable()
select new
{
a.TemporaryPermitID,
a.TemporaryPermitNumber,
a.EventName,
a.FromDate,
a.ToDate,
a.Organization,
a.PermitDescription
};
entrys1 = entrys1.Where(a1 => a1.TemporaryPer mitNumber.ToString()。包含(pattern.TemporaryPermitNumber.ToString()));
entrys = entrys1.AsQueryable();

不确定它是否是最佳解决方案,但它有效且我很高兴< BR>结果

I have this query where I'm trying to see if their is part of the value

var entrys = from a in _Context.Permits
                    orderby a.Organization ascending
                    select new
                    {
                      a.PermitID,
                      a.PermitNumber
                            };

entrys = entrys.Where(a1 => a1.PermitNumber.Value.ToString().Contains(pattern.PermitNumber.ToString()));

Gives me error,
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

I've read other post that says:
hat error means LINQ to Entities doesn't know how to generate SQL for that method call.  You could materialize the query first (call ToList(), ToArray(), First() or something else that causes the query to be executed), so the data is in memory, and then do the concatination afterward. or use AsEnumerable()

But i'm not quite sure how to do it with my query.

Thanks

解决方案

OK I figured it out.  I converted it to AsEnumerable then did my checking and then just converted it back AsQueryable.

 var entrys1 = from a in entrys.AsEnumerable()
                         select new
                            {
                                  a.TemporaryPermitID,
                                  a.TemporaryPermitNumber,
                                  a.EventName,
                                  a.FromDate,
                                  a.ToDate,
                                  a.Organization,
                                   a.PermitDescription
                              };
entrys1 = entrys1.Where(a1 => a1.TemporaryPermitNumber.ToString().Contains(pattern.TemporaryPermitNumber.ToString()));
entrys = entrys1.AsQueryable();

Not sure if its the best solution, but it works and im happy


这篇关于如何将int转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆