我对LINQ投影有什么选择? [英] What options do I have for LINQ projections?
问题描述
在LINQ中,我想投影与数据库表中不同的名称.我可以将其用作列标题的友好名称".具有%"或可能带有"(空格)的名称.下面的查询将无法编译.
In LINQ, I'd like to project different names than those from the database tables. "Friendly names" that I can use for column headers. Names that have "%" or possibly a " " (space). The query below won't compile.
是否有可能这样?还是我在所有内容上都使用可怕的_下划线?
Is something like that possible or am I stuck using the dreaded _ underscore for everything?
dim query = from p in ctx.SomeTable() _
select ProductName = p.product_name, _
[Expiration Date] = p.expiration_date,
[% of sales] = p.pct_sales
推荐答案
当然可以通过使用select子句为数据库的字段投影不同的名称.
It's certainly possible to project different names for the fields of the database by using the select clause.
Dim query = From p in ctx.SomeTable() _
Select ProductName = p.product_name, ExpirationData = p.expiration_date
但是,选择的名称仍然必须是有效的VB标识符.这样一来,您将无法使用空格或%
However the names that are chosen still must be valid VB identifiers. So that will preclude you from using a space or %
这篇关于我对LINQ投影有什么选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!