小编fir*_*pol的帖子

Umbraco按语言获取字典项目,怎么样?

在Umbraco v6中,可以使用以下命令获取dictionaryitem:

umbraco.library.GetDictionaryItem("EmailSubject");
Run Code Online (Sandbox Code Playgroud)

这将检索"EmailSubject"的正确值,具体取决于用户访问umbraco网站的文化.

现在我正在编写一个简单的电子邮件类库,我不关心System.Threading.Thread.CurrentThread.CurrentCulture,我不想在获取值之前始终设置CurrentCulture.它有效,但我不喜欢这种方法.我正在写一个简单的邮件库.对于每个邮件收件人,我认为设置这样的文化并不是很有效.

我找到的解决方案(在线搜索,我遗失了来源抱歉)是以下示例:

//2 = the 2nd language installed under Settings > Languages, which is German in my case
var sometext = new umbraco.cms.businesslogic.Dictionary.DictionaryItem("SomeText").Value(2);
Run Code Online (Sandbox Code Playgroud)

我创建了一些帮助方法,使其更容易:

private string GetDictionaryText(string dictionaryItem, string language)
{
    //try to retrieve from the cache
    string dictionaryText = (string)HttpContext.Current.Cache.Get(dictionaryItem + language);

    if (dictionaryText == null)
    {
        dictionaryText = new umbraco.cms.businesslogic.Dictionary.DictionaryItem(dictionaryItem).Value(GetLanguageId(language));
        //add to cache
        HttpContext.Current.Cache.Insert(dictionaryItem + language, dictionaryText, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
    }

    return dictionaryText;
}

private int GetLanguageId(string language)
{
    int languageId = 1; //1 …
Run Code Online (Sandbox Code Playgroud)

c# umbraco

7
推荐指数
2
解决办法
7625
查看次数

LINQ to SQL:IQueryable - 字符串包含 - 方法不支持到 SQL 的转换

亲爱的 LINQ 或 linq2sql 专家,你能帮我解决这个问题吗?

我有 Book 类,每本书都有一个列表,我想要的是找到作者列表中作者姓氏包含特定 searchAuthor 字符串的书籍,如下所示:

string searchAuthor = "foo";
IQUeryable books = BookStaticRepository.SelectAll();

books.Where(r => r.Authors.Any(x => searchAuthor.Contains(x.lastname, StringComparison.OrdinalIgnoreCase)));
Run Code Online (Sandbox Code Playgroud)

我得到这个错误是什么:

方法“Boolean Contains(System.String, System.String, System.StringComparison)”不支持对 SQL 的转换。

我已经尝试过相同的操作,但使用 IEnumerable,并且它有效。由于性能问题,我不得不切换到 IQueryable...我需要它与 IQueryable 一起工作。

感谢您的帮助。

linq-to-sql

4
推荐指数
1
解决办法
8230
查看次数

标签 统计

c# ×1

linq-to-sql ×1

umbraco ×1