[英]Difference in Where clause and foreach look up in C# entity framework
我有一段代碼:
var component = (from components in dataContext.Component select components)
.Where(x => x.Name.ToString().Equals(componentCode));
其中Component
是非常簡單的對象 。
在mysql數據庫表中(以utf8編碼-utf8_unicode_ci)
我有以下記錄: szkło3mm (帶有波蘭語ł )。
當我嘗試使用上面的代碼查找此記錄時,我什么也沒得到。
沒有波蘭語字符的記錄效果很好,但是當我用foreach
進行操作時,得到的結果是:
var component = (from components in dataContext.Component select components);
foreach(Component comp in component)
{
if (comp.Name.ToString().Equals(componentCode))
componentPrice = (decimal)comp.Price;
}
有沒有一種方法可以僅使用linq代碼獲得結果,而無需遍歷表。
好的,我找到了解決方案-在連接字符串中添加了“ Charset = utf8”,它可以正常工作。 在主題中找到的解決方案: 實體框架C#插入數據俄語編碼問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.