Hotw创建动态Linque要设置 [英] Hotw to create Dynamic Linque To set

查看:82
本文介绍了Hotw创建动态Linque要设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们创建了内联查询和动态SQL。我们的功能是这样的

We have inline queries and dynamic SQL created. Our Function is like this

Public Function SQL_GetEvents_LinqToSql(Optional Top As String = "", Optional lSelect As List(Of String) = Nothing, Optional lJoins As List(Of String) = Nothing, Optional Where As String = "DateStart > GETDATE() AND Active = 1 AND es.DeletedOn IS NULL", Optional OrderBy As String = "EventTitle") As DataTable
    Dim sSelect As String = ""
    If Not lSelect Is Nothing AndAlso lSelect.Count > 0 Then
        sSelect = ", " & String.Join(", ", lSelect.ToArray())
    End If
    If lJoins Is Nothing Then lJoins = New List(Of String)
    lJoins.Add(" LEFT OUTER JOIN Images i2 ON e.EventID = i2.EventID AND i2.AzureURL <> '' AND i2.ImageType = 'Logo' ")
    Dim sJoins As String = ""
    If Not lJoins Is Nothing AndAlso lJoins.Count > 0 Then
        sJoins = " " & String.Join(" ", lJoins.ToArray())
    End If
    Dim SQL As String = ""
    SQL &= " SELECT " & Top
    SQL &= " i2.AzureURL,"
    SQL &= " es.EventSeriesID,"
    SQL &= " e.EventID,"
    SQL &= " es.SeriesTitle AS EventTitle, "
    SQL &= " es.SEOPageName,"
    SQL &= " es.Description,"
    SQL &= " es.UserID,"
    SQL &= " es.Website,"
    SQL &= " es.URL_Registration,"
    SQL &= " es.DiscountURL,"
    SQL &= " es.Promocode,"
    SQL &= " es.PromocodeDesc,"
    SQL &= " es.bHasKidsCourse,"
    SQL &= " es.KidsCourseDescription,"
    SQL &= " es.YoutubeEmbed,"
    SQL &= " e.DateStart,"
    SQL &= " e.DateEnd,"
    SQL &= " e.Address,"
    SQL &= " e.City,"
    SQL &= " e.State,"
    SQL &= " e.Province,"
    SQL &= " e.CountryID,"
    SQL &= " e.AD_Expires,"
    SQL &= " e.bInheritFromEventSeries"
    SQL &= sSelect

    SQL &= " FROM Events e JOIN EventSeries es ON e.EventSeriesID = es.EventSeriesID "
    SQL &= sJoins
    SQL &= "WHERE e.bInheritFromEventSeries = 1 "

    If Where <> "" Then Sql &= " AND " & Where

    Sql &= " UNION "

    Sql &= " SELECT " & Top
    Sql &= " i2.AzureURL,"
    Sql &= " e.EventSeriesID,"
    Sql &= " e.EventID,"
    Sql &= " e.EventTitle,"
    Sql &= " e.SEOPageName,"
    Sql &= " e.Description,"
    Sql &= " e.UserID,"
    Sql &= " e.Website,"
    Sql &= " e.URL_Registration,"
    Sql &= " e.DiscountURL,"
    Sql &= " e.Promocode,"
    Sql &= " e.PromocodeDesc,"
    Sql &= " e.bHasKidsCourse,"
    Sql &= " e.KidsCourseDescription,"
    Sql &= " e.YoutubeEmbed,"
    Sql &= " e.DateStart,"
    Sql &= " e.DateEnd,"
    Sql &= " e.Address,"
    Sql &= " e.City,"
    Sql &= " e.State,"
    Sql &= " e.Province,"
    Sql &= " e.CountryID,"
    Sql &= " e.AD_Expires,"
    Sql &= " e.bInheritFromEventSeries"
    Sql &= sSelect.Replace(" es.", " e.")

    Sql &= " FROM Events e "
    Sql &= sJoins
    Sql &= " WHERE e.bInheritFromEventSeries = 0 "
    If Where <> "" Then Sql &= (" AND " & Where).Replace(" es.", " e.")

    If OrderBy <> "" Then Sql &= " ORDER BY " & OrderBy
    Return Sql
End Function



现在我想使用LINQ作为带有正确表关联的dbml文件。

现在我想要使用Linq喜欢以下添加filterextra



http://stackoverflow.com/questions/13995212/technique-for-dynamically-adding-a-join-to-a-linq-query [ ^ ]





请告诉我它的紧急


Now I want to use LINQ as I dbml file with correct table association.
Now I want to make use of Linq like the following adding filterextra

http://stackoverflow.com/questions/13995212/technique-for-dynamically-adding-a-join-to-a-linq-query[^]


Please tell me its urgent

推荐答案

听起来像你想使用 DynamicExpression类 [ ^ ]构建动态Linq查询。



如何:使用表达式树构建动态查询(C#和Visual Basic) [ ^ ]

使用LINQ实现动态搜索 [ ^ ]
Sounds like you want to use DynamicExpression class[^] to build dynamic Linq queries.

How to: Use Expression Trees to Build Dynamic Queries (C# and Visual Basic)[^]
Implementing Dynamic Searching Using LINQ[^]


这篇关于Hotw创建动态Linque要设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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