Solved

How would I write a IS LIKE query in entity?

Posted on 2014-10-13
2
104 Views
Last Modified: 2014-10-16
I know how to write the part of the query but not the IS LIKE

Thanks for the help.



NLAMEMEntities2 oe = new NLAMEMEntities2();
Test5 d = oe.Test5.ToList().WHERE IS LIKE(x => x.Names == TextBox5.Text.ToString()).First();


        d.Names = Label2.Text.ToString();
        d.Phone = Label3.Text.ToString();

Open in new window

0
Comment
Question by:bmanmike39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 250 total points
ID: 40377686
'Like' is a imprecise operator and is not implemented that way.  You can either use StartsWith, EndsWith or Contains

var names=new List<String>(new string[] {"Bob", "Henry", "Bill", "Cliff", "Clifford"});

var starts = names.Where(x => x.ToUpper().StartsWith("B"));
var Ends = names.Where(x => x.ToUpper().EndsWith("B"));
var Contains = names.Where(x => x.ToUpper().Contains("B"));

Open in new window


The results of the above will be:
Starts=
Bob
Bill
Ends=
Bob
Contains=
Bob
Bill
0
 
LVL 34

Accepted Solution

by:
it_saige earned 250 total points
ID: 40377693
You would use Contains(), e.g. -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace LinqExample
{
	class ComplexData
	{
		public string Names { get; set; }
		public string City { get; set; }
		public int Account { get; set; }
	}

	class Program
	{
		static void Main(string[] args)
		{
			List<string> namesArray = new List<string>() { "Bob", "Joe", "Dan", "Rick" };
			List<ComplexData> DataObject = new List<ComplexData>();
			DataObject.Add(new ComplexData() { Account = 1, City = "Ramhurst", Names = "Rick,Peter,Paul" });
			DataObject.Add(new ComplexData() { Account = 2, City = "Paulson", Names = "David,Dan,Daryl" });
			DataObject.Add(new ComplexData() { Account = 3, City = "Petersburg", Names = "Nuk,Nit,Nat" });
			DataObject.Add(new ComplexData() { Account = 4, City = "Salsburg", Names = "Joe,Diane,Tracy" });
			DataObject.Add(new ComplexData() { Account = 5, City = "Templeton", Names = "Larry,Nancy,Bob" });
			var newList = (from item in DataObject
						from name in namesArray
						where item.Names.Contains(name)
						select item);
			foreach (var item in newList)
				Console.WriteLine(string.Format("Account - {0}; City - {1}; Names - {2}", item.Account, item.City, item.Names));
			Console.ReadLine();
		}
	}
}

Open in new window

Produces the following output:Capture.JPG-saige-
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question