Solved

How would I write a IS LIKE query in entity?

Posted on 2014-10-13
2
101 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
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 33

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
About delegates in c sharp 3 35
Replace &lt; with < 14 56
Split in Javascript 5 31
C# guarantee sql connection close 6 27
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now