哪里实体框架存储属性名称,并选择在SQL列之间的映射? [英] Where does Entity Framework store the mapping between property names and the columns it selects in SQL?

查看:92
本文介绍了哪里实体框架存储属性名称,并选择在SQL列之间的映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一些自定义扩展到使用的ObjectQuery的ToTraceString()来生成LINQ代码原始的SQL EF(4.3)。

I am trying to build some custom extensions onto EF (4.3) using ObjectQuery's ToTraceString() to generate raw SQL from LINQ code.

我注意到,虽然在某些情况下,列在SQL的名称相匹配查询的元素类型的属性名称,在其他情况下,它们被命名为喜欢的事情C1,C2等,这使得它很难为我做的生成的SQL东西。有谁知道如何把这些列名映射回属性名称(我只在乎能平元组,如匿名类型没有什么帮助,我什么都不需要层次做到这一点)。

I've noticed that while in some cases the names of the columns in SQL match the property names of the query's element type, in other cases they are named things like C1, C2, etc. This makes it very difficult for me to do anything with the generated SQL. Does anyone know how to map these column names back to property names (I only care about being able to do this for flat tuples such as anonymous types if that helps, I don't need anything hierarchical).

这依赖于私人/内部反射一个解决方案是完全可以接受的。我知道我可能与将来的EF版本进行调整。另外,我只使用MS SqlServer的(2008+),如果它帮助。

A solution that relies on private/internal reflection is perfectly acceptable. I understand that I may have to adjust it with future EF releases. Also, I am only using MS SqlServer (2008+) if it helps.

推荐答案

我刚才问并回答了类似的问题(你可以忽略所有的数据表中的东西,但它显示的映射是如何使用它可能是有用):

I just asked and answered a similar question (you can ignore all the DataTable stuff, but it might be useful in that it shows how the mapping is used):

实体框架 - 以IQueryable的数据表

原来的职位,说明如何获得在对象属性的立场和SQL语句中列的位置之间的映射可以在这里找到:

The original post that shows how to get at the mapping between the object property positions and SQL statement column positions can be found here:

如何实体框架管理映射查询结果匿名类型?

注意:第二个链接只提供在位置的映射(作为整数值)的对象属性和SQL语句中列之间...你会必须使用反射来获得实际的对象属性的名称,然后做一些字符串分析对SQL语句来获得SQL语句的列名(你可以使用这个正则表达式,但可能是矫枉过正)。

Note: The second link only provides a mapping of the positions (as integer values) between the object properties and the SQL statement columns...you'll have to use reflection to get at the actual object property names and then do some kind of string analysis on the SQL statement to get the SQL statement column names (you could use regular expressions for this, but that might be overkill).

这篇关于哪里实体框架存储属性名称,并选择在SQL列之间的映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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