-2

I am trying to create LINQ statement. with where clause like this

  p.Users = db.UserFSMs
      .Where(t => t.UserName.Contains(userORFile.Split('_')[2]))
      .Select(new Models.UsersFSMFinal { Email=t.Email });

But the compiler is not recognizing t. How can I create above query that will work with where?

t3chb0t
  • 16,340
  • 13
  • 78
  • 118
user786
  • 3,902
  • 4
  • 40
  • 72

1 Answers1

1
  • you have to declare t=> again with the .Select(t => new

  • I wrote the same LINQ statement but on my Database and the inserted data will be from a textbox. It worked fine

     var allData = db.Patients
         .Where(t => t.firstName.Contains(TextBox1.Text))
         .Select(t => new
         {
              t.firstName,
              t.lastName
         });
    
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
Mai
  • 39
  • 8
  • I am not inserting into database, I am sending data to view. so I can't send `var` typed to view I need concrete type. – user786 Aug 28 '16 at 10:00
  • @Alex While this is not the best formulated answer, it's technically correct. Just read the beginning - insert `t =>` in your `Select`. Then you'll get a runtime exception, but that's another story. – Ivan Stoev Aug 28 '16 at 10:17