Is there any difference in (asymptotic) performance between
var a = Orders.OrderBy(order => order.Date).First()
and
var y = Orders.Where(order => order.Date == Orders.Min(x => x.Date)).ToList();
i.e. will First() perform the OrderBy()? I'm guessing no. MSDN says enumerating the collection via foreach och GetEnumerator does but the ...
Hi,
I have a fairly simple Linq query (simplified code):
dim x = From Product In lstProductList.AsParallel
Order By Product.Price.GrossPrice Descending Select Product
Product is a class. Product.Price is a child class and GrossPrice is one of its properties. In order to work out the price I need to use Session("exchange_rate...
I've posted this before, but I worded it poorly. I'm trying again with a more well thought out structure.
I have the following code and I am trying to figure out the shorter linq expression to do it 'inline'. Please examine the "Run()" method near the bottom. I am attempting to understand how to join two dictionaries together based on a...
I have a Linq collection of Things, where Thing has an Amount (decimal) property.
I'm trying to do an aggregate on this for a certain subset of Things:
var total = myThings.Sum(t => t.Amount);
and that works nicely. But then I added a condition that left me with no Things in the result:
var total = myThings.Where(t => t.OtherProper...
The help file that came with Dynamic Linq in the CSharpSamples.zip does not show any examples of using contains or like.
Are there any simple workarounds for doing this? i.e where (col like @col) doesn't work.
...
What is faster and should I sacrifice the Linq standard to achieve speed (assuming Dictionary lookup is truly faster)? So let me elaborate:
I have the following:
List<Product> products = GetProductList();
I have a need to search for a product based on some attribute, for example, the serial number. I could first create a dictionary...
Hi,
I have the following LINQ query:
List<string> Types = (List<string>)Directory.GetFiles(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727")
.Where(x => System.IO.Path.GetFileNameWithoutExtension(x).Contains("Microsoft"))
.ToList<string>();
How could I modify this ...
I have a query that pulls back a user's "feed" which is essentially all of their activity. If the user is logged in the query will be filtered so that the feed not only includes all of the specified user's data, but also any of their friends.
The database structure includes an Actions table that holds the user that created the action a...
I have the a simple LinqToSQL statement that is not working. Something Like this:
List<MyClass> myList = _ctx.DBList
.Where(x => x.AGuidID == paramID)
.Where(x => x.BBoolVal == false)
.ToList();
I look at _ctx.DBList in the debugger and the second item fits both parameters.
Is there a way I can dig into this more ...
I have a column of type Bit (called BBoolVal in this example).
I have a LinqToSQL Statement Like this:
var query = List<MyClass> myList = _ctx.DBList
.Where(x => x.AGuidID == paramID)
.Where(x => x.BBoolVal == false);
When I look at the sql it ends up like this (I added the spacing and changed the names):...
I often get in a position when I need to know why my LINQ doesnt work as intended...
I use object collections and extensions.
I dont want spend more than couple of minutes on it. LINQ supposed to make developer's life easier not harder.
I hoped VS 2010 will have it fixed but I now use RC and it still doesnt let me type LINQ and check ...
[WebMethod]
public string GetAuthToken(string username, string password)
{
var db = new LogicDB();
//var results = from u in db.Users
// where u.Username == username && u.Password == password
// select u;
User u = db.Select
.From<User>()
.W...
I have a XDocument that looks like this:
XDocument outputDocument = new XDocument(
new XElement("Document",
new XElement("Stuff")
)
);
That when I call
outputDocument.ToString()
Outputs to this:
<Document>
<Stuff />
</Document>
But I want it to look like this:
...
I have two tables ('keywords', 'titles') that are related via a mapping table. I am trying to return a list of Map_Keywords_Title (the mapping table's object) based on the results of a join.
Until I added the last part with typedQuery it was just returning objects of anonymous type. I want it to return items of type 'Map_Keywords_Title...
ParameterExpression parameter = Expression.Parameter(typeof(Product), "x");
MemberExpression Left = Expression.MakeMemberAccess(parameter, typeof(Product).GetProperty("Name"));
ConstantExpression Right = Expression.Constant(value, typeof(String));
BinaryExpression expression = Expression.Equal(Left, Right);
...
Has anybody got an idea of how to create a .Contains(string) function using Linq Expressions, or even create a predicate to accomplish this
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expr...
I have an IEnumerable< Person> object. The Person class has a Designation proeprty.
I want to select distinct Designation values from IEnumerable< Person> and assign that to a DropDownList. How can I do it?
...
I ended up with this horrible code below, I can't get a better result now.
What is a better way of doing that?
It's about this part of my database:
EDIT
A Patient has a Subscription to multiple MonitoringObjects. Target records refer to these Subscriptions. I want to retrieve the target records with the newest date per Subscription ...
Is it possible to wrap some "external" API code AND a LINQ data context into a transaction? In my case, I want to wrap the ASP.NET 2.0 Membership API calls AND my own LINQ operations into a transaction.
...
I've seen many examples in LINQ but i'm not able to reproduce the same result in vb.net.
I have following code:
Dim context As New MyModel.Entities()
Dim rnd As New System.Random()
Dim gardens As List(Of Tuin) = (From t In context.Gardens Where _
t.Approved = True And _
...