Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Linq_Deferred_Execution_Demo()
- {
- List<String> items = new List<string> { "Bob", "Alice", "Trent" };
- var results = from s in items select s;
- Console.WriteLine("Before add:");
- foreach (var result in results)
- {
- Console.WriteLine(result);
- }
- items.Add("Mallory");
- //
- // Enumerating the results again will return the new item, even
- // though we did not re-assign the Linq expression to it!
- //
- Console.WriteLine("nAfter add:");
- foreach (var result in results)
- {
- Console.WriteLine(result);
- }
- }
- Before add:
- Bob
- Alice
- Trent
- After add:
- Bob
- Alice
- Trent
- Mallory
- Single(x => x.id == id)
- Where(x => x.id == id).Single()
- [TestMethod]
- public void QueryComplexityTest()
- {
- var users = _dataContext.Users;
- Func<User, bool> funcSelector = q => q.UserName.StartsWith("Test");
- Expression<Func<User, bool>> expressionSelector = q => q.UserName.StartsWith("Test");
- // Returns IEnumerable, and do filtering of data on client-side
- IQueryable<User> func = users.Where(funcSelector).AsQueryable();
- // Returns IQuerible and do filtering of data on server side
- // SELECT ... FROM [dbo].[User] AS [t0] WHERE [t0].[user_name] LIKE @p0
- IQueryable<User> exp = users.Where(expressionSelector);
- }
- from outerloopitem in outerloopitems
- from innerloopitem in outerloopitem.childitems
- select outerloopitem, innerloopitem
Add Comment
Please, Sign In to add comment