I'm new to anonymous classes, and today I think I ran into the first case where I felt like I could really use them. I'm writing a method that would benefit from storing temporary data inside of a class, and since that class doesn't have any meaning outside of that method, using an anonymous class sure made sense to me (at least at the ...
I'm having an issue with my linq query. I am trying to filter objects based on selected values. We use a query model which returns a System.Linq.Expressions.Expression and uses it to create an nhibernate query. Here is my linq expression.
x =>
(
request.InitialLoad
...
I have object Country, which has Areas. Areas has Provinces. Provinces has Cities, and Cities, and Cities has hotels.
I want to filter list of regions to have only objects with property userHaveBeenThere set to true(Areas,Provinces,Cities,and hotels.
I'm going to bind this list to treeview.
The worst part of this algorith situation, ...
Most will recommend caching as a list. I know that is a solution and may be the one I go with. But, what if one wants to be able to treat a cached linq-to-sql with full IQueryable (IEnumerable?) functionality?
If one does try to cache the raw result, an error "Query results cannot be enumerated more then once".
So, to make clear my que...
Consider a DataTable which contains columns:
RefID : string
RefName : string
RefDate : DateTime
The DataTable does not contains any primary key.
I have another List<string> named ExcludeMe.
I would like to filter my DataTable and exclude all of the rows where values in RefId Column around found in the ExcludeMe list.
How ca...
Given a collection, is there a way to get the last N elements of that collection? If there isn't a method in the framework, what would be the best way to write an extension method to do this?
...
Hi im having a problem with ordering with linq.
I have a object with two datetime fields. One just stores the date (e.g. 8/2/2010) and leaves the time as all 0's
While the other datetime field is created when the record is made and has the time on it as well. The idea of these two field are because I may want to add a "Headline/article"...
I am using SharePoint Web Services to get some list items out of SharePoint for a project i am working on.
I am using using LINQ to XML to parse the resulting XML to be put into a datasheet.
The problem i am running into is when trying to parse an item that isn't required in SharePoint...
var fields = from item in results.Descendants...
Hi....
Lets say i have a database in c:\database.mdf
what is the difference between using context.DatabaseExists("c:\database.mdf")
or just simply checking with File.exists("c:\database.mdf") ?
i ask this because i get strange behavior form DatabaseExists method :
it tells me sometimes that c:\database.mdf exists but it's not there, ...
I've 2 tables with same column's name, for example, both table A and table B has column's name "Test". I want to select column Test from both table A and B to entity class. How can I do this?
...
When I used linq to retrieve xml, <CDATA[[ ]]> is removed, which is what I want to achieve.
But when I save the file, <CDATA[[ ]]> becomes <CDATA[[ ]]> in the xml file.
Whether or not I explicitly append with <CDATA[[ ]]> before saving gives me the same result.
Tried appending with <CDATA[[ ]]> but still gives me th...
I have a variable number of OR conditions that I want to put together into one Linq query.
How do I do this in a loop? Basically, the final query is to be:
IQueryable<MyObject> Q;
Q = Q.Where(q => (condition1) || (condition2) || ..... || (condition N));
Something like:
For (int i = 0; i < someNumber; i++) {
Q = Q.Where(q => (exis...
Hi,
I am little new to linq and was wondering how i can select the application in the following xml based on the application name using Extension Methods (not using the query expression)
<applicationlist>
<application>
<name>test1</name>
<ele1>852</ele1
<ele2>http://localhost/test1</ele2>
</application>
<application>...
Hello
I have an mvc-page that lists categories, and I would like to have it to count the number of products per category. It's IQueryable.
<% foreach (var item in Model.Categories) { %>
.....
<td><%: item.CategoryName %></td>
<td><%: item.Products.Count() %></td>
It lists:
5
5
Instead of:
3
2
Any Ideas how I can "partition" it per ...
Consider the following:
// select a subset of the DataTable
var subset = DataTable.Where(...).Select(row => new
{
Id = Convert.ToInt32(row["Id"]),
Name = row["Name"].ToString(),
Email = row["Email"].ToString()
});
// or create a new object
var subset = new {
Id = 1,
Name = "something random",
Email = "name@domai...
hi; i try to run my codes. My program more slowly runnig. i need to give performance also write less codes in GetAliSpReqs(), GetMaintData();GetAccess....GET(...
How can i write more effective below codes. They are too slow also not useful. forexample i try to write les than 1-2 line with GetAliSpReqs()? How can i ? please help me...
...
my xml is bellow:
<Demo>
<ClientCompanyId CompanyId="1">
<MyMenu>
<module Text="Basic Settings" ModID="Mod1" ModuleID="1" MenuType="0" Perm="False">
<menu Text="Forms" MID="1-1" ParentID="Mod1" MenuDescription="Mod" ModuleID="1" MenuType="0" Perm="False">
<Leaf Text="LookUp" MID="1-3" ParentID="1" MenuDescription="" ModuleID="1" MenuTyp...
Hi all,
I have collection of custom objects(assets) which I want to group with LINQ.
Custom object has standard properties like id, name and cost property.
When grouping I want to calculate cost for each group, so I'm using little trick like this:
from a in assets
group a by a.AssetId into ga
select new Asset()
{
...
Hi,
I have xml element:
<.SECTIONS>
<.SECTION ID ="1" NAME="System Health" CONTROL-TYPE="Button" LINK="http://www.google.co.in/">
<.DATAITEMS>
<./DATAITEMS>
<./SECTION>
<./SECTIONS>
I want to get the all attribute names of SECTION Element. as ID,NAME,CONTROL-TYPE,LINK at server side using ...
Hi All,
How can I get a List from all nodes in a tree using LINQ?
My classes are:
class Node
{
public class Node()
{
Children = new List<Node>();
}
public List<Node> Children { get; set;}
}
class Tree
{
public Tree()
{
Roots = new List<Node>();
}
List<Node> Roots { get; set;}
}
...