Hello,
I have a table of items with several properties but to keep it short, it has property price.
I want to group a List<Item> into groups of price ranges.
The catch is that the price ranges (ceilings ...) have to be dynamically generated.
When the ceilings are static, things work fine (Using LINQ)
decimal[] ceilings = new decimal[...
I've seen examples of the reverse question, but they don't help me with this direction.
I've got a List where T has an int weight. I'd like to divide this into lists of 5 grouped by weight.
if I have the following T's with respective weights
A:1
B:2
C:3
D:4
E:5
F:6
G:7
H:8
I:9
J:-11
I want {A,B,C,D,E,F,G,H,I,J} to be sorted to {{J,A,B,...
I'm writing a tool, and the first part of that tool is to collect all the header files in our public API. The problem is, two of the header files have duplicate file names (but they reside in different folders). This will cause a problem when creating a dictionary.
Originally I wrote a foreach loop to collect FileInfo instances into a ...
I have code like:
var result = from x in Values where x.Value > 5 select x;
Then, I want to check:
if(result.Count > 0) { ... }
else if(result.Count == 1) { ... }
else { throw new Exception(...); }
However, I get errors like:
error CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'int'
Can I do this...
How can I give an alias name to fields selected from a DataTable using LINQ?
...
Is there any way to convert the result of a LINQ to DATATABlE without stepping through each element?
...
I'm executing an update stored procedure from LINQ to SQL and I need to know the records affected after the update is called.
I'm using dbml designer to generate the LINQ code.
...
In the following code, How can I check for null reference exception in a "good practice" way?
if (primaryMenu.ChildNodes.Any(p=>VirtualPathUtility.GetFileName(p.SiteURL).Equals(selectedPage)))
{
primaryMenuTab.Attributes.Add("class", "current");
}
The way I am doing it currently is (But JetBrain ReSharper doesnt't wana accept it an...
The end goal for this post is to override the ToString() method of a concrete implementation of a generic base class while still being able to search the implementation using Linq flattening technique. So if you read this and see a better way let me know. I'm using Telerik controls for Silverlight and they won't change their api to allow...
I have two tables, one parent "Point" and one child "PointValue", connected by a single foreign key "PointID", making a one-to-many relation in SQL Server 2005.
I have a LINQ query:
var points = from p in ContextDB.Points
//join v in ContextDB.PointValues on p.PointID equals v.PointID
w...
I have a very simple linq query that gets data from two datatables (orderHeader & OrderDetails) and joins them together. What I would like to do is take the order items for each order and pass them to a method for processing.
Here is the query:
var results = from orderHeader in dtOrderHeader.AsEnumerable()
join orderDetails in dtOrderD...
Consider the below
if(type== "S")
{
lstItem.ItemsSource = (from item in Items
where item.Property1 == "SomeValue"
select item);
}
else
{
lstItem.ItemsSource = (from item in Items
where item.Property2 == "SomeOtherValue"
select item);
}
As can be figured out that the on...
I have a situation wherein to accomodate the need of dynamic addition of columns to a table, I am putting the columns values as rows in a table.
As an example, storing of columns of an Address Table would be in the format:
ID PropertyName
1 HouseNo.
2 Street
3 City
4 State
5 Country
Now, if I need to create an O...
The model being passed to my view is of type tblUser - so I expected that I would be able to:
<% Model.tblLogins.Where(l => l.date > DateTime.Now.AddDays(-7)).Count() %>
However, the .Where() part is not available as an option? I have the following in my web.config but hasnt helped:
<add namespace="System.Linq"/>
<add namespa...
I have a simple SQL statement.
Select distinct value from tablename where value not like '%TEST%'
How do I write this in Linq to SQL syntax.
I tried the below statement but it doesnt seem to work.
var p = (from c in tablename where !(c.value.ToUpper().Contains("%TEST%"))
select c.Value).Distinct().ToList()
...
I have the following code that uses the Observable class from System.Reactive. I'm using the November 2009 Silverlight 3 toolkit.
private IObservable<Event<EventArgs>> _ob;
private IDisposable _proxy;
...
private void Init()
{
_ob = Observable
.FromEvent<EventArgs>( x_Grid, "LayoutUpdated" )
.Throttle( 2000 );...
Hello all.
Me again with a dumb question/scenario I need advice on.
I have the following that pulls back the contents of a column:
return getappropriateuserfield.tblAutoComplete
.Where(p => p.MemberId == memberid && p.ACItem == acitem)
.Select(p => p.ACColumn)
.Distinct()
...
I'm using sqlmetal.exe to generate a DataContext class from a sqlserver database to use with LINQ. I have a bunch of stored procedures that in some cases returns a primary key column that is a NOT NULL INT, such as this one:
CREATE PROCEDURE spDDIs_Find(@DDINumber VARCHAR(64)) AS
IF NOT EXISTS (SELECT ID FROM tDDIs WHERE DDINumber = @D...
What is the best way to group an array into a list of array of n elements each in c# 4.
E.g
string[] testArray = { "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s8" };
should be split into if we take n=3.
string[] A1 = {"s1", "s2", "s3"};
string[] A2 = {"s4", "s5", "s6"};
string[] A3 = {"s7", "s8"};
May be a simple way using LINQ?
...
Hi,
I have two tables Students and Origami. Origami has Foreign Key of Students table. Each student can make one or more origami for each month.
Students sample data:
StudentId, FirstName, LastName
187 , John , Maslow
196 , Crystal , Hood
195 , Sarah , Lewis
Origami sample data:
OrigamiId, StudentId, CreationDate, NumberOfOriga...