I'm having a rough time figuring out exactly how to do a LINQ query on a DataTable and return a full row while having the WHERE clause test on a sum.
My code:
transactionsToRemove.AddRange(paymentTransactionResults
.AsEnumerable()
.Where(...)
.GroupBy(r => (decimal)r["AccountNumber"]));
There are multiple transactions ...
I have a LINQ to Entities query (using EF 4) that has some pretty complicated set-based filtering going on. The code compiles just fine, but when I try to run it, I get the following error:
Unable to create a constant value of type 'ITextEntity'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
...
Hi,
I have three tables Student, TimeSheet and TimeRecord.
Talbe columns:
Student : StudentId, FirstName,
LastName
TimeSheet: TimeSheetId,StudentId, IsActive
TimeRecord: TimeRecordId,TimeSheetId, BonusHour(type int), CreationDate
Table relationship:
Student 1:N TimeSheet (FK StudentId)
TimeSheet 1:N TimeRecord (FK TimeSheetId)
...
I have a Func defined as follows:
Func<Foo, bool> IsSuperhero = x => x.WearsUnderpantsOutsideTrousers;
I can query IEnumerables like this:
IEnumerable<Foo> foos = GetAllMyFoos();
var superFoos = foos.Where(IsSuperhero);
But when I try to supply the same Func to the Where method of an IQueryable, I get:
'Cannot convert source type ...
I have an array string[] with values that are mostly convertible to integers.
var values = new [] {"", "1", "2", "a", "3"};
I need to convert values to an array of integers, discarding any items that aren't convertible. So I end up with
var numbers = new [] {1, 2, 3};
What would be the most efficient (quickest and clean code) way ...
Context: C# 3.0, .Net 3.5
Suppose I have a method that generates random numbers (forever):
private static IEnumerable<int> RandomNumberGenerator() {
while (true) yield return GenerateRandomNumber(0, 100);
}
I need to group those numbers in groups of 10, so I would like something like:
foreach (IEnumerable<int> group in RandomNu...
Hi,
I have a two objects as follows:
public class Item
{
public int ItemId {get;set;}
public string ItemName {get;set;}
public List<Tag> ItemTags {get;set;}
public DateTime DateCreated {get;set;}
}
public class Tag
{
public int TagId {get;set;}
public string TagName {get;set;}
}
These are LINQ-to-SQL objects,...
Say you have the following entities defined in a LINQ class:
Product
Customer
Category
Should I have one repository class for all:
StoreRepository
... or should I have:
ProductRepository
CustomerRepository
CategoryRepository
What are the pro & cons of each? In my case, I have several "applications" within my solution... the Stor...
I have the following example:
using (MyContext context = new MyContext())
{
var query = from entityA in context.EntityA.Include("TestProperty")
join entityB in context.EntityB on entityA.Id equals entityB.EntityAId
join entityC in context.EntityC on entityB.Id equals entityC.EntityBId
...
I have three tables Student, TimeSheet and TimeRecord.
Talbe columns:
Student : StudentId, AssignedId, FirstName,
LastName
TimeSheet: TimeSheetId,StudentId, IsArchive, IsComplete
TimeRecord: TimeRecordId,TimeSheetId, BonusHour(type int), CreationDate
Table relationship:
Student 1:N TimeSheet (FK StudentId)
TimeSheet 1:N TimeRecord...
So I got this crazy idea I could make make something cool work. I got tired of new selectlist(item, "blah", "blahblah") so I started writing an extension method (trying to get it more strongly typed) something like this ...
var selectList = projects.ToSelectList(p =>p.ProjectID, p =>p.ProjectName);
the extension method goes a little ...
I am using the ActiveRecord SubSonic3 templates. Everything was working just dandy, then I decided I wanted things to look a bit better. See my database has field that look like this:
SomeKey_id
SomeOtherKey_id
I wanted to clean it up so that it would instead be
SomeKeyID
SomeOtherKeyID
when accessing it through SubSonic.
So I ad...
I have a class
public class Item : IItem
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual bool IsActive { get; set; }
}
public interface IItem
{
Guid Id { get; set; }
string Name { get; set; }
bool IsActive { get; set; }
}
public class ItemMap : ClassMap<Item>
{
...
Hi I have a datagridview which binds XML manually.
I wish to sort out the columns by clicking column header.
here is the method i wrote: when you click column header, it grabs column header and sorting data by that column header.
I also put a toggle switch(direction) on that, so when user click again , the data can be sorted in differ...
Hi,
I have the following query, I'd like to sum the NULL value also. Some TimeSheet don't records in TimeRecord and some tr.TimeIn and tr.TimeOut are NULL.
The query select only TimeSheet that has reords in TimeRecord. How I can have it select everything, and sum up the NULL value as well. So, the SUM of NULL will be just zero.
Table ...
I am reading this asp.net article on building your first asp.net mvc 2 website and I came across a Linq query that uses the Include method in the query. I have used some linq, but I have never used the Include method and would like a better explanation. Does it translate to an join in linq? What is the benefit? Here is the query from...
I was reading about Expression Tree feature and how you can create delegates using lambda expressions. I still can't get as to in what scenario it is useful and in what real world example should I use it.
...
Suggestion either in C# or VB.NET are welcome.
Table relationship:
Student 1:N TimeSheet (FK StudentId)
TimeSheet 1:N TimeRecord (FK TimeSheetId)
Dim query = From s In db.Students _
Let pair = (From ts In db.TimeSheets _
Join tr In db.TimeRecords On tr.TimeSheetId Equals ts.TimeSheetId _
Where ...
What are your suggestions for designing linq code in project?
Especially, I`m interesting in code design of big and complex linq queries?
For example, you know, that you need to write a lot of huge linq stuff, maybe some of your code will have duplicate parts, maybe not, and you need:
Make the code easily supportive - means, if you ne...
I'm using LINQ to query my database, and I don't want all the records returned all at once. Instead, user should be able to select Next 5 and Previous 5 using buttons. As of this moment I have selected the first 5 rows in the Item table in the databas like this:
private void ShowItems()
{
var items = (from p in db.Items
...