首页 \ 问答 \ 词典词典(Dictionary of dictionaries)

词典词典(Dictionary of dictionaries)

我有一个像这样抓取的资源文件:

var rs = <somewhere>.FAQ.ResourceManager
     .GetResourceSet(CultureInfo.CurrentUICulture, true, true);

我想将它解析成字典词典,但我无法弄清楚如何。 这就是我正在尝试的:

var ret = rs.OfType<DictionaryEntry>()
  .Where(x => x.Key.ToString().StartsWith("Title"))
  .ToDictionary<string, Dictionary<String, string>>(
    k => k.Value.ToString(),
    v => rs.OfType<DictionaryEntry>()
      .Where(x => x.Key.ToString().StartsWith(v.Value.ToString().Replace("Title", "")))
      .ToDictionary<string, string>(
        key => key.Value,
        val => val.Value
      )
  );

因此,如果我理解正确, k应该引用DictionaryEntry,因此我应该能够像k.Value一样取消引用它并在每个外部字典的条目中制作我的字典我对资源文件做另一个查询,因此keyval也应该是DictionaryEntry类型。

在引用val.Value我收到错误“无法从方法组中选择方法。您是否打算调用该方法?” 虽然这应该是一个属性,而不是一个方法。

救命?

ps作为解释,我的资源文件看起来像这样:

TitleUser:  User Questions
TitleCust:  Customer Questions 
User1: Why does something happen? Because… 
User2: How do I do this? Start by…
Cust1: Where can I find…?  It is located at… 
Cust2: Is there any…? yes, look for it…

这意味着我首先得到一个部分列表(通过查找以“标题”开头的所有键),并为每个我寻找一个问题列表


I have a resource file I grab like this:

var rs = <somewhere>.FAQ.ResourceManager
     .GetResourceSet(CultureInfo.CurrentUICulture, true, true);

and I want to parse it into a dictionary of dictionaries but I can't figure out quite how. this is what I'm trying:

var ret = rs.OfType<DictionaryEntry>()
  .Where(x => x.Key.ToString().StartsWith("Title"))
  .ToDictionary<string, Dictionary<String, string>>(
    k => k.Value.ToString(),
    v => rs.OfType<DictionaryEntry>()
      .Where(x => x.Key.ToString().StartsWith(v.Value.ToString().Replace("Title", "")))
      .ToDictionary<string, string>(
        key => key.Value,
        val => val.Value
      )
  );

so if I understand this correctly, k should refer to a DictionaryEntry and thus I should be able to dereference it like k.Value and to manufacture my dictionary in each of the outer dictionary's entries I do another query against the resource file, thus key and val should also be of type DictionaryEntry.

In referencing val.Value I get the error "Cannot choose method from method group. Did you intend to invoke the method?" though that should be a property, not a method.

help?

p.s. as an explanation, my resource file looks sort of like this:

TitleUser:  User Questions
TitleCust:  Customer Questions 
User1: Why does something happen? Because… 
User2: How do I do this? Start by…
Cust1: Where can I find…?  It is located at… 
Cust2: Is there any…? yes, look for it…

which means I first get a list of sections (by looking for all keys that start with "Title") and for each I look for a list of questions


原文:https://stackoverflow.com/questions/21359194
更新时间:2022-12-09 15:12

最满意答案

hibernate是一种面向对象的数据库访问框架。
from order o where o.customer.cid=3;
order--是指一个实体对象,你的实体类中应该有一个order 的类。hibernate通过这个order自动映射到数据库中order类对应的表。

o--是order取的一个别名。
o.customer--你的order类中一定包含有一个customer的对象,对应在order表中就应该有customer的一个主键cid作为order表的外键。
(作为良好的编码习惯,数据库表中表名、字段最好不要用数据库的关键字命名)

其他回答

这是SQL语句的语法 
from 数据表 where字段名=字段值 order by字段名[desc]

这里的order是支实体对象,o是order实体对象的重命名
在这里order被认为是一个实体对象。
当然一般情况下尽量不要用sql语句的关键字。你即便要用order做实体类,也尽量写成Order,这也是java规范
name 不在group by中,,,,,需要特别处理 。。。。。。。。。
猜测这里数据结构应该是Order{Customer customer ....} Customer{Int cid.....}
这里的order肯定是个表名,order是sql语句的关键字意思是按照哪一列排序,要和by一起使用,比如 from table_name order by age.

相关问答

更多
  • hibernate是一种面向对象的数据库访问框架。 from order o where o.customer.cid=3; order--是指一个实体对象,你的实体类中应该有一个order 的类。hibernate通过这个order自动映射到数据库中order类对应的表。 o--是order取的一个别名。 o.customer--你的order类中一定包含有一个customer的对象,对应在order表中就应该有customer的一个主键cid作为order表的外键。 (作为良好的编码习惯,数据库表中表名 ...
  • 我没有可供测试的hibernate安装程序,但似乎可以这样做: http : //docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-aggregation I don't have a hibernate setup available to test, but it seems like you can: http://docs.jboss.org/hibernate/core/3.3/reference/ ...
  • show databases不是有效的JPQL语句,并依赖于您正在使用的数据库。 您可以使用本机查询session.createSQLQuery(...)直接与数据库交谈,但在这种情况下,您将失去Hibernate在数据库独立实现方面的优势。 show databases is not a valid JPQL statement and dependent on the database you are using. You can use a native query session.createSQL ...
  • 首先你的问题没有完全清除,首先在这里定义你的数据库模型,并从你的查询我已经知道 hql.append(" DOC.id, "); 这里不会添加最后一个Coma hql.append(“DOC.id”); 这里 hql.append(" FROM ").append(DocumentoAssinanteTO.class.getName()).append(" DA "); 你不需要通过调用class.getname()方法来获取类的名称,你只需要在这里调用bean或bean的名称。 你的内部联接中存在 ...
  • 可以说userId的值是“abc12” 给定您的代码,名为hql的字符串的值将变为:“FROM com.pck.Person where userId = abc12” 如果您获取该字符串的值并尝试将其作为任何数据库的查询运行,则大多数人都无法理解abc12是一个字符串。 通常它会被解释为变量。 正如其他用户提到的那样,包括单引号会产生所需的查询,但建议的分配参数值的方法是: String hql = "FROM com.pck.Person where userId = :id" query.se ...
  • 未定义用户别名。 试试吧 String hql = "from User user inner join user.cars car where car.id in (:carIds)"; Query query = session.createQuery(hql) query.setParameterList("cars", carIds); 其中carIds是一个集合(而不是第三次尝试中的字符串),其中包含汽车的ID。 The user alias is not defined. Try with S ...
  • 事实上,根据Hibernate关于Polymorphic查询的文档: Hibernate查询可以在from子句中命名任何Java类或接口。 该查询将返回扩展该类或实现该接口的所有持久化类的实例。 以下查询将返回所有持久对象: from java.lang.Object o Named接口可以通过各种持久化类来实现: from Named n, Named m where n.name = m.name 但是因为接口没有被映射(因此未知),所以你需要在你的HQL查询中使用完全限定的名字: from qua ...
  • 不要连接HQL查询。 请改用命名参数 。 它是Hibernate中查询对象模式的一种实现。 对于你的情况: Session session = sessionFactory.getCurrentSession(); String selectQuery = "FROM Account as account WHERE account.username = :usernameParam"; Query query = session.createQuery(selectQuery); query.setPar ...
  • 您可以在映射中使用access="noop"来指定仅限查询的属性(这是一个秘密的,未记录的功能,请参阅HHH-552 ): 更新:只需澄清一下,使用以下实体: public class EntityWithHqlOnlyProperty implements Serializable { private Long id; private Str ...
  • 请尝试使用别名查询 - min(case when t.Rank > 0 then t.Rank else 10000 end) Please try the query with aliases - min(case when t.Rank > 0 then t.Rank else 10000 end)

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)