如何用资源中的字符串替换select查询中的值? [英] How to replace value in select query with string from resources ?

查看:107
本文介绍了如何用资源中的字符串替换select查询中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何用以下资源中的字符串替换select Query中的值:





how to replace value in select Query with string from resources like this example:

strings.ResourceManager.GetString(s.StartStatus, strings.Culture);





什么我试过了:



i试过这个:





What I have tried:

i tried this :

var Query = DB1.view_items_history
            .Where(u => u.stitems_ID == itemID &&  u.OpDate >= From && u.OpDate <= To)
            .Select(s => new CLSItemsHistory
            {
                stitems_ID = s.stitems_ID,
                stitems_Status = s.stitems_Status,
                stitems_Name = s.stitems_Name,
                stitems_Type = s.stitems_Type,
                stitems_Type_name = s.stitems_Type == 0 ? strings.STOCKS : s.stitems_Type == 1 ? strings.STOCKS_WITH_SERIAL : "",
                stitems_Code = s.stitems_Code,
                stitems_NationalCode = s.stitems_NationalCode,
                DetunitID = s.DetunitID,
                UnitName = s.UnitName,
                ID = s.ID,
                mID = s.mID,
                OpType = s.OpType,
                OpName = strings.ResourceManager.GetString(s.OpType, strings.Culture),
                OpDate = s.OpDate,
                r_branche_ID = s.r_branche_ID,
                branche_Name = s.branche_Name,
                IncmQnt = s.IncmQnt,
                OutQnt = s.OutQnt,
                cost = s.cost,
                TotalCost = s.TotalCost,
                FromStore = s.FromStore,
                fstore_Name = s.fstore_Name,
                ToStore = s.ToStore,
                tstore_Name = s.tstore_Name,
                StartStatus = strings.ResourceManager.GetString(s.StartStatus, strings.Culture),
                EndStatus = strings.ResourceManager.GetString(s.EndStatus, strings.Culture)

            });





但出现此错误:

<系统.NotSupportedException:'LINQ to Entities无法识别方法'System.String GetString(System.String,System.Globalization.CultureInfo)'方法,并且此方法无法转换为商店表达式。 '



but this error appear :

System.NotSupportedException: 'LINQ to Entities does not recognize the method 'System.String GetString(System.String, System.Globalization.CultureInfo)' method, and this method cannot be translated into a store expression.'

推荐答案

足够简单。将ResourceManager.GetString调用的值分配给LINQ表达式之外的字符串变量,然后只使用该变量代替所有ResourceManager.GetString调用。



您收到该消息的原因是因为底层数据库引擎不知道ResourceManager是什么或如何将对它的任何调用转换为SQL代码。
Easy enough. Assign the value of the ResourceManager.GetString call to a string variable outside of the LINQ expression, then just use the variable in place of all of your ResourceManager.GetString calls.

The reason you get that message is because the underlying database engine doesn't have a clue what a ResourceManager is or how to translate any call to it into SQL code.


这篇关于如何用资源中的字符串替换select查询中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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