如何在Linq中编写SQL Concat? [英] How do I write a SQL Concat in Linq?

查看:53
本文介绍了如何在Linq中编写SQL Concat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linq中编写concat的最佳方法是什么?我知道官方的说法是你做不到,但我听说有很多方法可以实现它,我需要帮助才能做到这一点.我有一条SQL语句,内容如下:

What is the best approach to take to write a concat in Linq? I know that the official word is that you can't but I've heard that there are ways you can accomplish it and I need help to do this. I have a SQL Statement that reads as follows:

CONCAT(
   [event_organiser] ,
   ' ', DATEPART(dd,[event_start]),
   '/', DATEPART(mm, [event_start])) 
   AS organiser_info

我需要在Linq中创建它,但是我不确定如何基于当前设置.这是我当前的选择语句.

I need to create this in Linq but I'm not sure how to based on my current setup. Here is my current select statement.

var datacontext = db.tbl_events.AsQueryable();

IQueryable<EventsViewModel> theevent = (

             from v in datacontext
             where v.event_start == null
             select new EventsViewModel
             {
                 event_idx = v.event_idx,
                 event_name = v.event_name
                 ...concat goes here..
             });

推荐答案

感谢您对此问题的反馈,您的评论和示例使我根据您的展示获得了答案.这是适合我的特定情况的

Thank you for the feedback on this question your comments and examples led me to the answer based on what you have shown me. Here is what worked for my particular scenario

next_charterer_info = string.Concat(p.fixture_charterer ?? "", " ", p.fixture_start.Value.Day, "/", p.fixture_start.Value.Month),

再次感谢

这篇关于如何在Linq中编写SQL Concat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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