Tagged Questions
0
votes
1answer
24 views
Matching the order of one array to another using linq
I have an int array of ID's that are ordered properly. Then I have an an array of unordered objects that have ID properties.
I would like to order the objects by ID that match the order of the int ...
1
vote
1answer
67 views
Combining data using linq
I have some code that combines two arrays with an identifier array called seqNum2. I cant quite get it to combine a third array using linq, the third array in my code would be grossNGL2. When I take ...
4
votes
2answers
59 views
How to write a dynamic Lambda Expression to access Nth Parent entity?
I have an application using nhibernate and linq to do my queries on database. Everything works fine but I have the follow model mapped (with auto-related):
public class A
{
public virtual int Id ...
3
votes
3answers
69 views
linq “let” division, then orderby ascending
I have this data, and I'm using linqToExcel:
I'm trying to get inflation divided by GDP...then order them ascending, but I can't get it right.
var people = from x in ...
0
votes
0answers
52 views
LINQ to SQL command text
We have several stored procs that take multiple inputs and I am looking for a solution to view the sproc with all inputs for easier debugging.
So if we have the following we copy and paste ...
0
votes
1answer
32 views
Given a base class how do I find the most specialized subclasses of it?
I can find all the classes that are subclasses of BaseClass with something like
var subclasses = Assembly
.GetAssembly(typeof(BaseClass))
.GetTypes()
.Where(t => ...
0
votes
2answers
59 views
Regex in Linq statement?
I'm writing a short C# to parse a given XML file. But 1 of the tag values can change, but always includes words "Fast Start up" (disregarding case and spaces, but needs to be in the same order) in the ...
3
votes
4answers
114 views
LINQ fastest way to update lots of records (>2m)
I have this loop:
using(var db = new MainContext())
{
var q = db.tblInternalURLs;
foreach (var rec in q)
{
db.ExecuteCommand("UPDATE tblInternalURLS SET hash = '" + ...
1
vote
2answers
44 views
Select common elements for 2 or more departments from list group by then having count
I have a class that looks like so:
{
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
...
0
votes
2answers
14 views
searching for an unnamed nested XElement by a specific XAttribute
Here is what my XML looks like (Yes, I know the XML is ugly). I'm trying to search and remove any nodes from this XDocument that have the isConstField attribute set to "Y" without iterating through ...
0
votes
3answers
30 views
Get top 5 created subsites in sharepoint without for loop
I need an easy way to get the latest 5 created webs.
I know every web has a Created Date property.
I would like to do this without a foreach becahse there can be 1000 subsites.
Any idea?
using ...
1
vote
4answers
60 views
how to validate if lambda query returns null
I retrieve data from database with lambda like
var obj = DBContext.MyTable.Where(x => x.ID == 2).SingleOrDefault().MyColumn;
Actually , in MyTable , there is no ID with 2 .
So I got this ...
2
votes
2answers
33 views
Casting Ado.net DataReader to IDataRecord giving strange result
I have a query that I run against the database, and I can see that there is a record for 31/05/2013. When I run this query from C# with ADO.NET, and then use the following code, I am missing the ...
1
vote
1answer
53 views
SubQuery and Group by in linq
This query was written in the our system some time ago but the performance of this query is getting poor with a little increase in data. My investigation shows (CodeCount) where query firing another ...
10
votes
1answer
254 views
C# Replace all elements of List<string> with the same pattern with LINQ
I have a C# List with thousands of strings:
"2324343"
"6572332"
"45122" ...
I would like to replace all of them with brackets around them, so then they would look like
"(2324343)"
"(6572332)"
...
2
votes
2answers
46 views
Join two lists based on a condition other than equals
In a nutshell...
I have a list of source control folders which are gathered from changesets using the TFS API in the structure of:
$/ProjectFolder/BranchName/Project A
...
0
votes
1answer
33 views
Check if IEnumerable has ANY rows without enumerating over the entire list
I have the following method which returns an IEnumerable of type T. The implementation of the method is not important, apart from the yield return to lazy load the IEnumerable. This is necessary as ...
2
votes
3answers
46 views
Linq to Entities - insert all objects with TagID in string[] into an ICollection<Tag>
Tag object
public virtual int TagID { get; set; }
public virtual string Name { get; set; }
public virtual string NamePlural { get; set; }
I have an ICollection<Tag> - and a string[] ...
1
vote
3answers
47 views
dynamically adding controls under loop in C#
I am developing a windows application where I want to create some controls dynamically inside a loop.
The code I am trying is
private Label newLabel = new Label();
private int txtBoxStartPosition = ...
1
vote
2answers
35 views
What is best way access different database on different engine but with similar structure
I usually work with MySql, but also with SQL Server, Oracle and Access, the database structure is almost the same. My database stores configuration and recorded data of a SCADA application ...
0
votes
2answers
48 views
How to convert temp table with case statement SQL to Linq?
I'm very newbie in Linq and don't know how to solve some problems even very easy in MS SQL query.
Select e.EmployeeID
, e.EmployeeName
, e.Division
, e.DepartmentCode
, e.DesignationGrpCode
Into ...
2
votes
2answers
41 views
varbinary pdf from database has been crash?
This is how I retrieve varbinary pdf from my database and view in my asp.net page ,
byte[] pdfFile= null;
var obj = DBContext.MyTable.Where(x => x.ID == 1 ).SingleOrDefault().pdfColumn;
pdfFile = ...
1
vote
3answers
40 views
Efficient way to merge table like datastructure using linq
Allow me to present you with my atrocious logic first:
public void MergeLotDataList(List<SPCMeasureData> sPCMeasureDataList)
{
double standMaxTotal = 0.0;
double ...
3
votes
2answers
46 views
How to count rows in a table in an html file C#
When there is a compound table inside an html file how can one count the rows of the parent table.
What I mean by a compound table; a table in which other tables are contained within some of its ...
1
vote
1answer
27 views
Convert string join utility function into LINQ equivalent
So I have a helper function that takes a particular list, performs a loop and returns a string joined with comma without duplication.
public static string ...
1
vote
1answer
36 views
multiple query with linq
I hope someone can help me with the below.
My tables are like,
(Job)
JobID
CustomerID
JobPartID
Job -> JobPart (One to Many)
(JobPart)
JobPartID
JobID [Foreign Key – ref JobID(JobID)]
...
0
votes
3answers
59 views
Using Lists and Linq, writing efficient code
I have created a quick console application, which creates 10000 younger people and 10000 older people and adds them to two separate lists. I then perform some queries to obtain information based on ...
1
vote
1answer
25 views
Need Help Filtering A LINQ Query Using An Entity Framework Navigation Property
I need help filtering a LINQ query on an Entity Framework (EF) navigation
property. The tables were created first (not code-first).
For this problem, let's use the characters from The Office.
...
0
votes
0answers
23 views
How can I build the permutation in query syntax?
I've tried to write a method which returns the permutation of a given enumerable as simple as possible. the code:
using System.Collections.Generic;
partial class Permutable /* private methods */ {
...
0
votes
4answers
130 views
How to exchange the items of enumeration by interating only once?
I'm trying to exchange the ordering of particular items of an IEnumerable.
Given an IEnumerable<int> a; of the elements:
1, 2, 3, 4, 5
and what I want to do is write a exchange iterator ...