Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How would I write a IS LIKE query in entity?

Posted on 2014-10-13
2
Medium Priority
?
117 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 1000 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 1000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

704 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