Solved

How would I write a IS LIKE query in entity?

Posted on 2014-10-13
2
99 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
Comment Utility
'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 32

Accepted Solution

by:
it_saige earned 250 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

11 Experts available now in Live!

Get 1:1 Help Now