Build your silver light application
View more presentations from Pranay Rana.
List<string> members = new List<string>() { "pranay", "Hemang" }; bool ISCollectionEmpty = members.Any();So by using method I get to know my collection has any element or not.
var deptList = from dept in dbcontext.Departments where dept.Employees.Any() select dept; foreach (var item in deptList) { Console.WriteLine(item.Name + " : " + item.Employees.Count()); }Output:
SELECT [t0].[Id], [t0].[Name] FROM [dbo].[Department] AS [t0] WHERE EXISTS( SELECT NULL AS [EMPTY] FROM [dbo].[Employee] AS [t1] WHERE [t1].[DeptId] = [t0].[Id] )
--Searching string contains abc i.e prabcfg, abcpr Select * from table name where columnname like '%abc%' --Searching string starts with abc i.e abcpr, abcrana Select * from table name where columnname like 'abc%' --Searching string ends with abc i.e prabc, ranaabc Select * from table name where columnname like '%abc' --Searching string with wildcard char _ i.e abec,abfc Select * from table name where columnname like 'ab_c'Now in LINQ to achieve same thing we have function like StartsWith, EndsWith and Contains. So LINQ query is
//Searching string contains abc i.e prabcfg, abcpr var user = form u in users where u.Name.Contains("abc"); //Searching string starts with abc i.e abcpr, abcrana var user = form u in users where u.Name.StartsWith("abc"); //Searching string ends with abc i.e prabc, ranaabc var user = form u in users where u.Name.EndsWith("abc");But with the LINQ I cannot able to achieve the last case(wildcard char _ ) and many more that I can do in like condition of the t-SQL.
var emplist = from emp in dbcontext.Employees where SqlMethods.Like(emp.FirstName, "pr_nay") select emp;When you execute the statement you can see the the t-sql statement same as above i.e wildcard statement listed above, you can view the query in the sql profiler.