Anyone care to guess what currentIndex is at the end of execution?
int[] ints = new int[] { -1, 12, 26, 41, 52, -1, -1 };
int minInt = ints.Min();
It's 110. Does anyone know why?
Wrapped it a main function below
using System;
using System.Linq;
class Sample {
public static void Main()
{
int[] ints = new int[] {...
Hello,
I have a rather annoying issue with LinqToSql. I have created a class that is derived from the class in the DataContext.
The problem is that as soon as I use "InsertOnSubmit(this);" on this derived class I get a NullReferenceException.
I've seen some people with the same issue. However they've used a custom constructor and so...
HI there I am hoping for some help with a query I have.
I have this query
var group =
from r in CustomerItem
group r by r.StoreItemID into g
select new { StoreItemID = g.Key,
ItemCount = g.Count(),
ItemAmount = Customer.Sum(cr => cr.ItemAmount),
RedeemedAmount = Custome...
Hello,
I have an ObservableCollection of Task objects. Each Task has the following properties:
AssignedTo
Category
Title
AssignedDate
I'm giving the user an interface to select which of these fields they was to sort by. In some cases, a user may want to sort by up to three of these properties. How do I dynamically build a LINQ state...
i use this code to fill dropdownlist
ViewData["projectType"] = new SelectList
(_dataManager.Project.ProjectTypeList(), "Id", "Name");
but what i must do if i want to use not one table column but two or more columns? for example
ViewData["projectType"] = new SelectList
(_dataManager.Project.ProjectTypeList(), "Id", "Name1"+"N...
I've been working for quite a while now with LINQ. However, it remains a bit of a mystery what the real differences are between the mentioned flavours of LINQ.
The successful answer will contain a short differentiation between them. What is the main goal of each flavor, what is the benefit, and is there a performance impact...
P.S.
I ...
This should be pretty simple, but I am new at LINQ. I have a List<FillStruct> of FillList structs. I'd like to use LINQ to create a new List<NewFillStruct> where instead of having the number of buys and sells, I would have one variable containing the sum.
For example, if the FillStruct structure has
buy = 4
and
sell = 2
then t...
hi,
here is my scenario
i got
Table1
id
name
Table2
id
family
fid
with one to many relationship set between Table1. id and Table2.fid
now here is my WCF service Code
[OperationContract]
public List<Table1> GetCustomers(string numberToFetch)
{
using (DataClassesDataContext context = new DataClassesDataContext())
{
...
Suppose I have an automatically-generated Employee class based on the Employees table in my database.
Now suppose that I want to pass employee data to a ShowAges method that will print out name & age for a list of employees. I'll retrieve the data for a given set of employees via a linq query, which will return me a set of Employee inst...
Hi,
Suppose I have an entity object defined as
public partial class Article
{
public Id
{
get;
set;
}
public Text
{
get;
set;
}
public UserId
{
get;
set;
}
}
Based on some properties of an Article, I need to determine if the article can be ...
Not sure if what I am trying is possible or not, but I'd like to reuse a linq expression on an objects parent property.
With the given classes:
class Parent {
int Id { get; set; }
IList<Child> Children { get; set; }
string Name { get; set; }
}
class Child{
int Id { get; set; }
Parent Dad { get; set; }
string Name { get; set; }
...
Let's say I have a Customer table which has a PrimaryContactId field and a SecondaryContactId field. Both of these are foreign keys that reference the Contact table. For any given customer, either one or two contacts may be stored. In other words, PrimaryContactId can never be NULL, but SecondaryContactId can be NULL.
If I drop my Custo...
This is fine, it produces a left join
var q =
from c in categories
join p in products
on c equals p.Category into ps
from p in ps.DefaultIfEmpty()
select new { Category = c, ProductName = p == null ? "(No products)" : p.ProductName };
But what about if I wanted to do something like this:
...
on p.date between c.s...
I could swear this was working the other day:
var resultSet =
(from o in _entities.Table1
where o.Table2.Table3.SomeColumn == SomeProperty
select o
).First();
SelectedItem = resultSet.Table2.SomeOtherColumn;
I am getting a null reference exception on the last line: resultSet.Table2 is null.
Not only am I sure that al...
I'm VERY new to Linq. I have an application I wrote that is in VB.NET 2.0. Works great, but I'd like to switch this application to Linq. I use ADO.NET to load XML into a datatable. The XML file has about 90,000 records in it. I then use the Datatable.Select to perform searches against that Datatable. The search control is a free fo...
I am using Linq to select and process lines from a text file. My txtfile is two columns delimitted by the pipe character "|". The File contains the following:
HAbbe|11
GABBOT|22
DABDA|33
RAchant|44
RADA|55
DABDA|66
You will notice that line 3 and line 6 have a duplicated ID(Column 1). I want to use linq to initially read the posted t...
I'm wondering how to best tackle this, since what I have now works great for a hard-coded column in my view -- I'm wondering how I can extend it to allow the column to be dynamic.
CONTROLLER:
var dc = new DataContextDC();
return View(dc.items.Where(i=>i.IsPublic == true));
VIEW:
<% foreach (var grp in Model.GroupBy(s => s.GroupColum...
I am trying to achieve the following...
_4S.NJB_Request request =
(from r in db.NJB_Requests
where r.RequestId == referenceId
select r).Take(1).SingleOrDefault();
Getting the following exception...
Message:
The null value cannot be assigned to a member with type System.Int32 whic...
Hello Friends,
I was wondering if i can consolidate below 2 linq statments into 1 statment. I am sure it should be possible, but various attempts i am unable to manage.
var prevProvisionsBySubBook = (from provision in prevProvisions
group provision by provision.SubBook
into subBookGrouping
...
I have a Dictionary<int, MyClass>
It contains 100,000 items
10,000 items value is populated whilst 90,000 are null.
I have this code:
var nullitems = MyInfoCollection.Where(x => x.Value == null).ToList();
nullitems.ForEach(x => LogMissedSequenceError(x.Key + 1));
private void LogMissedSequenceError(long SequenceNumber)
{
...