Solved

How would I write a IS LIKE query in entity?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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