As we know you can't add an extra clause like .Where() or .First() to a compiled query, because that changes the query and forces a recompile. What I would like to know is which methods can be used to "close" a compiled query.
I know most people use either .AsEnumerable() or .ToList(), but which other methods work as well? Can I use .A...
Hi,
is it possible to define a LINQ statement for the following problems WITHOUT using a foreach loop?
public class GroupObject
{
public String name;
public List<String> letters;
public void test()
{
List<GroupObject> myGroups = new List<GroupObject> {
new GroupObject {
name="test1",
...
Linq does a lot of clever things such as returning the result of the Count-property using the Count() method on a IList.
Is there a good source that gives an overview of this optimizations?
It would be very interesting because as before I knew the above, I never used Count() and thus often returned a List<T> than only an IEnumerable<T> ...
I have the following code:
if (collection["Filter"] == "2") {
presentations = presentations.Where(x => x.Speaker.FirstName.StartsWith("B")).
OrderBy(x => x.Speaker.FirstName);
}
this generates the following sql:
SELECT [t0].[Description], [t0].[EventId], [t0].[Id], [t0].[PresentedOn],
[t0].[Slug], [t0].[SpeakerId], ...
Hi,
I'm trying to create a query using linq 2 nhibernate which generate a sql like:
select * from table
where id in (1, 2, 3, 4)
At the moment I have this code:
var vouchers = Session.Linq<Voucher>()
.Where(x => campaignIds.Contains(x.VoucherGroup.Campaign.Id))
.ToA...
What I currently have looks a bit like this:
if(userLikesBananas)
{
return from fruit in basket
select new Fruit
{
AteBanana = Bowl.Any(b => b.OwnedBy == user && b.Contains(fruit) && fruit.Type == FruitType.Banana),
...
...
//lots of properties
...
I have reproduced my problem in a console app. Following is the code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqSample
{
class Program
{
static void Main(string[] args)
{
string query = "Maine, Maryland, Massachusetts, M";
var qu...
This is the pseudo-SQL I want to generate:
SELECT * FROM Table WHERE Column1 = @Value1 OR Column2 = @Value2
The problem is, sometimes the second one should not be included. I was hoping to chain together .Where() clauses like so:
var query = context.TableName;
query = query.Where(t => t.Column1 == value1);
if (NeedsToBeIncluded(valu...
My Title may be slightly off but here is what I am trying to do. I have a L2S Method that would be for every table that I would like to write once. This is to set a soft lock column where I will also need a Read and UnLock method. Here is what I have so far:
public static void LockRow(string TableName, int TablePrimaryKey)
{
...
Hey all,
I'm currently working my way through the learning curve that is LINQ and I could really use some assistance. I don't know if what I want is possible, but if I had to wager, I bet it is.
I currently have a list of objects called _tables and each of these objects has within it another list of objects exposed through the propert...
Guys,
Assuming I have the following ASP.NET HTML Code:
<html>
<head><title>Test Page</title></head>
<body id="bodyID">
<asp:Label runat="server" id="lbl1" text="First Name:" />
<asp:TextBox runat="server" id="txt1" /><br />
<asp:Label runat="server" id="lbl2" text="Last Name:" />
<asp:TextBox runa...
Hello,
I've been reading updates on Data Sets vs. Other ORM's like ADO.NET Entity Framework, but a lot of them refer to the older version, so with EF 4 as an option today, what is people's opinion for data sets vs. EF 4, which is better, worse?
I like EF 4 because:
The designer finally works well.
The variation of model options (POC...
I have a page where you can search for people. They can either get a list of all people, or filter it by certain criteria such as first or last name.
So far, I have been trying trying to use the technique detailed in this question.
So my code looks like
string firstname=...
string lastname=...
var people=from p in People.All()
...
Hey all,
Hopefully I can explain this to where it make sense, but I'm trying to get a list of objects out of a master list using a speicific and complex (complex to me, at least) set of criteria.
I have a Class called TableInfo that exposes a List of ForeignKeyInfo. ForeignKeyInfo has a string property (among others) called, Table. I...
I have a long LinqtoSQl query in which several parameters I'm not forcing the user to specify anything. I started using a Select Case statement that would test rather or not a parameter string's length > 0 or if it's an int > 0. But I realized that I would have to test for each possibility and create queries based on each.
I did some se...
I can never remember. How do i process each element in a string? I want to write
stringblah.Split('/n', Split('\n', StringSplitOptions.RemoveEmptyEntries))
.Each(s=>s.Trim());
...
I am moving an old ASP.net (C#) application from plain SQL queries to LINQ to SQL and am having some trouble with some of the more complex queries. In this case, I am trying to get a list of employees who have a certain set of skills. The user picks the skills to search for and the id's are supplied to the method that does the work. In t...
I have a simple value type:
[Serializable]
private struct TimerInstance
{
public TimerInstance(string str, long nTicks)
{
_name = str;
_ticks = nTicks;
}
private readonly string _name;
private readonly long _ticks;
public string Name { get { return _na...
Hey,
having some problems figuring this one out.
select *,(select top 1 chicken_nr from chicken_photo where chicken = code order by [sort]) as Photo from Chicken
Code is a column in Table Chicken
Basically getting the cover photo for this chicken.
To make it clearer, I want it to return multiple rows from table Chicken. But only a s...
I have a database with 2 tables:
Items
ItemDependencies
Items has key of ID
ItemDependencies have two columns: ItemId, and DependsOnItemId
I conver this to a collection:
IEnumerable<Item> items = GetItems();
each item has a: Dependencies property which is a
List<Item>
So i want to filter the initial items list to:
Given a ...