简体   繁体   English

查询连接字段(使用 SubSonic)

[英]Query Concatenated Field (using SubSonic)

Is there a way to query against a concatenated field using MS SQL?有没有办法使用 MS SQL 查询连接字段? For instance, what I want to do is something like:例如,我想做的是:

Select FirstName+' '+LastName as FullName from Attendees where FullName like '%Joe Schmoe%'

The above doesn't work.以上是行不通的。 What I have found works is:我发现的作品是:

Select * from Attendee where FirstName+' '+LastName like '%Joe Schmoe%'

but I can't figure out how to do that using a SubSonic SqlQuery.但我不知道如何使用 SubSonic SqlQuery 来做到这一点。 I have a number of joins and OR statements added dynamically that I don't want to have to write out the sql manually.我动态添加了许多连接和 OR 语句,我不想​​手动写出 sql。

Any help/ideas?任何帮助/想法?

how about this: 这个怎么样:

SELECT FullName 
FROM (SELECT FirstName+' '+LastName as FullName 
      FROM Attendees) X
WHERE FullName LIKE '%Joe Schmoe%'

You can just specify your condition in the Where part of your query as follows: 您可以仅在查询的“位置”部分中指定条件,如下所示:

List<Attendee> cardHolders = new YourDB()
  .Select
  .From<Attendee>()
  .Where(AttendeeTable.FirstNameColumn + " + ' ' + " + AttendeeTable.SurnameColumn + " AS FullName")
  .Like("%Joe Schmoe%")
  .ExecuteTypedList<Attendee>();

在SubSonic中似乎不可能

So late to the game but, if your using the SubSonic Select() you can use the SQL CONCAT to concatenate multiple columns before loading them into your DataTable for your DataGrid so for instance这么晚了,但是,如果您使用 SubSonic Select(),您可以使用 SQL CONCAT 连接多个列,然后再将它们加载到您的 DataGrid 的 DataTable 中,例如

    SubSonic.SqlQuery query = new SubSonic.Select(
     "CONCAT(FirstName, ' ', LastName) as FullName"
     ).From("Attendees").Where("LastName").Like("%Schmoe%");
    return query;

This was something I was looking for as well and just tried to see if the SubSonic would let me use the SQL CONCAT within the Select portion of the SubSonic.SqlQuery.这也是我一直在寻找的东西,只是想看看 SubSonic 是否会让我在 SubSonic.SqlQuery 的 Select 部分中使用 SQL CONCAT。 Hope this helps anyone else down the road.希望这可以帮助其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM