|
using System;
using System.Linq;
namespace TestMongo
{
using System.Text.RegularExpressions;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
public partial class Program
{
public static void DemoLinq(MongoCollection<ClubMember> collection)
{
var names =
collection.AsQueryable().Where(p => p.Lastname.StartsWith("R") && p.Forename.EndsWith("an")).OrderBy(
p => p.Lastname).ThenBy(p => p.Forename).Select(p => new { p.Forename, p.Lastname });
Console.WriteLine("People whos Lastname starts with 'R' and Forename ends with 'an'");
foreach (var name in names)
{
Console.WriteLine(name.Lastname + " " + name.Forename);
}
var regex = new Regex("ar");
Console.WriteLine("List of Lastnames containing the substring 'ar'");
IQueryable<string> regexquery =
collection.AsQueryable().Where(py => regex.IsMatch(py.Lastname)).Select(p => p.Lastname).Distinct();
foreach (string name in regexquery)
{
Console.WriteLine(name);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.