The more and more I use the LINQ the more and more I really enjoy it, and it's syntax. I do a lot of data comparisons on a day to day basis. What I would really enjoy is a tool that allows me to load a DataSet, and then query that DataSet at runtime with LINQ queries. I primarily just want a tool, and to be able to load my DataSets dynam...
I am using C# with the .NET 3.5 framework to write an application.
I have an enum like this,
public static enum SettingOneType { FooA, FooB, FooC }
I also have an XDocument that I load like this in a Load() method,
LoadXML(){
...
XDocument SettingsDocument;
if(File.Exists(path)
{
XElement SettingsElement = new X...
Hi,
Is it possible to write a lambda expression that will iterate through array of objects and replace all occurences of 'X', 'Y', ' ' and 'Z' in one of the properties?
E.g.
return query.Select(x => { x.SomePropertyName= x.SomePropertyName.Trim().Replace(' ', "_"); return x; }).ToList();
For some reason, a query above doesn't repla...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
XDocument xDocument = new XDocument(
new XElement("BookParticipants",
new XElem...
How would I get something like this to work so that I can dynamically alter the where-clause in this linq to sql query?
Dim AccountID = 1234
Dim AccountList
Select Case Types
Case 1
AccountList = (from a in dc.Accounts where a.ID = AccountID)
Case 2
AccountList = (from a in dc.Accounts where a.ID = AccountID An...
Given this structure..
I basically want to be able to take a list of items with multiple types, and create a new list that condenses down the sum of the values of each like-type. However the names of the types are dynamic (they may or may not have a specific order, and there is no finite list of them)
using System.Linq;
using System.C...
I have two lists (L1,L2) of an object A, L1 is used to store the list of objects(many to many relationship) before they are changed. L2 is the relationship after it has been changed. I need to keep the common elements but add the new ones and remove the ones that aren't in L2. I was wondering if there was a one liner I could use with LIN...
The below query fails with Null Reference Exception when there are elements in BOMIDs where MatID property is nothing.
I thought the 'x.MatID isnot Nothing AndAlso' would prevent the x.MatID.Process part of the where from being executed. There are a couple elements in the BOMIDs collection that where MatID is nothing.
Any thoughts?
Fro...
Im not so sure if this is a problem with nihibernate or linq(i would assume more linq but i may be wrong)
I Have website about boxing.
There are three tables in this example
Boxer (BoxerId among other properties)
Boxer_Match (holds a boxerId and MatchId - which is a composite key)
Match (MatchId among other properties)
Now currently i...
public class thing
{
public int Id{get;set;}
public decimal shouldMatch1 {get;set;}
public int otherMatch2{get;set;}
public string doesntMatter{get;set;}
public int someotherdoesntMatter{get;set;}
}
List<thing> firstList = new List<thing>();
List<thing> secondList = new List<thing>();
firstList.Add( new thing{ Id=1,shouldMatch1 = 1.11M,...
I have two tables in my database
Table:Documents
Id (int), DocName (nvarchar)
----------------------------
Table:AccessLogs
Id (int), DocId (int), AccessTime (DateTime)
----------------------------
How can I write a LINQ query that returns the last 10 accessed documents and fills in the access time from the accesslogs table?
I have m...
I've got an IEnumerable<T> containing a list of data elements with consistent intervals in one of the properties:
List<Interval> list = new List<Interval>
{
new Interval{ TIME_KEY = 600},
new Interval{ TIME_KEY = 605},
new Interval{ TIME_KEY = 615},
new Interva...
What is the linq equivalent of a SQL clause like WHERE UserName LIKE 'fr_d'?
I'm working with a dataset in memory rather than a SQL database so I don't think I can use something like where SqlMethods.Like(p.UserName, "Fr_d")
(Not that my installation of VS2008 is admitting that SqlMethods or even System.Data.Linq.SqlClient
exist at the...
This is the sort of thing I want to be able to do. I know you can qury linq results again, but because these results are in groups, I don't know how to. I think the best idea I can think of is to have a query to fetch everything, then do my if statement, then do another query that groups everything (so have 3 separate queries instead o...
Following up on a previous question, here is my general class structure..
http://stackoverflow.com/questions/3711224/combine-elements-in-a-list-based-on-type-and-summate-their-values-linq
I am trying to combine the items using their respective .Add methods, but because of Entity Framework considerations, I can only deal with base types...
The below code is a factory class that is delivers objects of type IGraph that have the GraphTypeAttribute implemented. Inside the static constructor of the GraphFactory, a list is built by using Linq to collect the appropriate classes to be delivered by the Factory. Normally without Linq I had a buch of loops and if-then's that could be...
I have a set of search criterias in this form:
member | value | operator
--------+---------+---------
height | 10 | >
height | 2 | <
name | Carl | ==
And I want to query all the objects that match any of these criterias.
Right now, I'm doing it by:
building an expression for each one
of the crit...
I'm having a hard time finding the right LINQ syntax to use for the following iterator block:
class Program
{
class Operation
{
public IEnumerable<Operation> NextOperations { get; private set; }
}
class Item { }
static Item GetItem(Operation operation)
{
return new Item();
}
static IEnum...
Hello,
I thought I would throw an omni-search on my data.
So I made a function that returns any match on a string.
ex.
var results = (from d in db.MyData
where new string[]{ d.DataField1.ToString(), d.DataField2.ToString(), ... }.Contains(searchTerm)
select d);
But when I try to iterate over it I get The expression of type 'System....
I'm testing for the existence of a user record in the following statement:
if (fromUser.AllFriends.Where(af => af.FriendUserID == toUserID).SingleOrDefault() == ???
Given the documentation:
Returns a single, specific element of a sequence, or a default value if that element is not found.
What does the bold text refer to? What the h...