我有一个包含描述列的表,我想选择不同的第一个单词。这是我将使用的SQL:
select distinct left(description,charindex(' ',description)-1) from tableA
如何将其转换为LINQ查询语法?
答案 0 :(得分:1)
简单的解决方案
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="D:\temp\uploads\vtour" path="/MySharedHTML"/>
</Host>
答案 1 :(得分:1)
在LINQ to Entities中,您可以将DbFunctions.Left与String.IndexOf Method (String)结合使用(根据CLR Method to Canonical Function Mapping支持),如下所示
var result = db.TableA
.Select(r => DbFunctions.Left(r.Description, r.Description.IndexOf(" ")))
.Distinct();