.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

"Like", "In" Expressions in Lambda statement

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :ASP.Net

Salam to all,

for my Lambda, i need to use Like Experssion, but this give me error, i dont know how to make this.

context.CreateObjectSet<ReportsManager_Entity>().Where(u => (u.ReportAdminInt like 123)).ToList();

also i need to use "in" expression (the same of 'in' experssion in sql) but also this give me an error

context.CreateObjectSet<ReportsManager_Entity>().Where(u => (u.ReportAdminInt in [1,2,3])).ToList();

please help me,


View Complete Post

More Related Resource Links

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

Basic Instincts: Lambda Expressions


Sample the basic concepts of lambda expressions, explore their benefits, and witness how to use them to write more expressive programs.

Timothy Ng

MSDN Magazine September 2007

Creating Dynamic Expressions for Lambda IQueryable Expressions



I have a ListBox that contains userNames which is inputted by a user during run time. This number of items in the ListBox is dependent on the user's input. These userNames will then be used in a Lambda expression like this:

var vHandleResult = vHandleResult.Where(a => a.UserName.Contains("userName"));

This works fine when there is only 1 user in the ListBox but doesn't produce the correct results when there are multiple items in the listBox. I tried manually creating the expression which should be written as this:

var vHandleResult = vHandleResult.Where(a => a.UserName.Contains("userName1") || a.UserName.Contains("userName2") || a.UserName.Contains("userName3") || a.UserName.Contains("userName4"));

I tried forming the "a.UserName.Contains("userName") expression as a string which is dependent on the number of the items (using foreach) and then just plug in the resulting string in the expression but it seems that it doesnt accept string as an expression.

Can someone help me identify the best approach for this?

Thanks in Advance!


Delegates and Lambda Expressions


What, exactly, relationship between Delegates and Lambda Expressions? More specifically, why is using a Lambda Expression in place of a Delegate allowed?

Finding a specific part in a a whole statement (Negating regex expressions)


Sorry for the lame title, but I couldn't think of another way to describe it. Basically I have been working on this all week and I am at the point now where I am not getting anywhere and need assistance.

I have this text which needs to be parsed;

text.set(Vector2(10,10), TEST, Vector2(20,20))

I am trying to find the second parameter of the method set which is a string(could be anything though besides an object definition like the first 2). I am able to find the other 2 parameters(just the numeric portions which is all I want) with this regex expression:


And I am able to find the "text." portion with this regex:


But what I cannot seem to do is to combine both of these negatively to give me the resulting string which should be "set(Vector2, TEST, Vector2)" which I could work with as output but ideally I would like just that second parameter. Important note is that this can't rely on positions as the second parameter wont always be available or a non-object declaration.

Here is a short back history if it is required and may help;

Basically I have designed a scripting language that works in the XNA framework for on the fly changes while running on windows. It all works fine and dandy with the way I hav

Various SQL Expressions

A comparison is a Boolean operation that produces a true or a false result, depending on the values on which the comparison is performed. A comparison is performed between two values of the same type; for example, you can compare two numbers, two characters, or the names of two cities. To support comparisons, Transact-SQL provides all necessary operators.

Passing Linq Statement between master and content page


I usually work with windows forms, and am just starting to work with ASP.Net, so appologies if this is a dumb question!

I have a master page which has a search button on it. The results of this are built up using a Linq statement and if there are any results, I want to display the results in a contents page.

On the masterpage, I have the following code:

Private _res

    Public Overridable ReadOnly Property SearchRes()
            Return _res
        End Get
    End Property

 Private Sub DoSearch()
   'some code to get a linq result

    If res.Any Then
            _res = res
            Server.Transfer("SearchResults.aspx", True)
            'no results
            LabelNoRes.Visible = True
        End If
 End Sub

On the SearchResults.aspx page I have this code.

Dim m As pxSite = CType(Page.Master, MasterPage)
        If m.SearchRes IsNot Nothing Then
            Label1.Text = "Results found = " & m.SearchRes.Count
        End If

m.searchRes is always nothing. 

What am I doing wrong here?


ReportViewer :: Failed to enable constraints. But my statement is valid!!

  • A
  • n error has occurred during report processing.
      • Exception has been thrown by the target of an invocation.
        • Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

    Why do I keep getting this error, even when not using any data on the report. When I run the query in SQL server I get a resultset. However when I try to render the report I get this error.


    Whats wrong with this statement


    Im trying to updated some old ASP pages with some new .net pages and cant seem to get this update statement to work. I need to update the current ASP code below and then once thats working im going to use that same statement in a procedure for all our new .Net pages..

    So can anyone see what im doing wrong by inserting the 2nd column to the update statement?

    strSqual = "update tas set date_completed='" & TransDate & ", trans_id=" & InsertedTransID & "' where date_completed is null and sercontract_id="& strContractID & " and DATEDIFF(dd,task_due_date,'" & strProcDate & "')<=14"


    I am trying to add an extra column to the update, but not sure if the syntax is correct.

    If Statement Issue



    This is very strange to me. I have spent 2hrs looking into this inside out , but dont seem to get it

    I have an if statement that inserts data into the database. But i check to make sure the name is not entered twice. Now when the name is already in the db, then it should insert else put out a message saying its already in the db

    My code works fine except that  when its not in the db, its inserts but still puts out the message that says "Name is already in use" Not sure if am not seeing something. But thought i did bring it to the forum. Here is my code...Pretty simple

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click

            Dim objConnection As SqlConnection
            Dim objCommand As SqlCommand
            Dim strSQLQuery1 As String


            ' If there's nothing to Add for then don't search
            ' o/w build our SQL Query and execute it.
            If String.IsNullOrEmpty(txtAdd.Text) Or Leadbank.SelectedValue = "000" Then


    statement cannot appear outside of a method body


    hi all,

      i am posting my vb.net problem .plz tell me how to resolve this :-

    Dim conn As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
        'Dim mysqlconnection As New SqlConnection(conn)
        'If mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();
        'Dim mySqlcommand As New SqlCommand("select CategoryId,CategoryName from Categories", mysqlconnection)
        'Dim mySqlDataAdapter As New SqlDataAdapter(mySqlcommand)
        'Dim mydataSet As New DataSet()

        'if mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();

    i m getting 5 errors in this code

    declaration expected in mySqlDataAdapter.Fill method; Gridview1.DataSource=ds; Gridview1.DataBind();

    how to multiple condition in if statement in asp.net C#



    i am using if condition to find out a time

    if(time=="08 AM)


    response.write"shift A";


    but problem is how can i put multiple condition in if like

    if(time=="06 AM" and "08 AM" and "07 AM")



    Hello, i need help changing the following code into a switch...case statementUndecided

    <script runat="server">
    void Page_Load()
        if (Page.IsPostBack)
        public String toSring()
        int intcomputerChoice=1;
           if (Page.IsPostBack)

    change to lambda in linq


    Hello my friends I tried to change this code to lambda but I could not pleaaaase help me:


      var inforeport = from m in db.Products where m.UnitPrice > info select new { unit=m.UnitPrice,name= m.ProductName };


    Toolbox: Online Scheduling, Jeff Smith's SQL Blog, Easy Regular Expressions, And More


    This month Scott looks at improving development skills, writing regular expressions, a web scheduling control and a SQL tips blog.

    Scott Mitchell

    MSDN Magazine November 2008

    Easy Async: Build Concurrent Apps From Simple F# Expressions


    In this article, the author explores how the F# language helps you create asynchronous function libraries that can be called seamlessly from any other .NET-compliant language.

    Chance Coble

    MSDN Magazine October 2008

    ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
    Sql Server  SharePoint  Silverlight  Others  All   

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend