I would like to build the where clase of a sql statement dynamically from hashtable in C#.
The key of the hash_table will be the column's name to be inserted and the value of hash_table will be value.
string sql_1="SELECT COL_1,COL_2 FROM MY_TABLE";
string sql_2="SELECT * FROM MY_TABLE WHERE COL_3='ABC'"; //note: some statment have wh...
I have a dictionary object of type Dictionary
and trying to use StreamWriter to output the entire content to a text file but failed to find the correct method from the Dictionary class.
using (StreamWriter sw = new StreamWriter("myfile.txt"))
{
sw.WriteLine(dictionary.First());
}
I can only retrieve the f...
Hi,
I have this XML:
<rootCategories>
<category id="1">
<category id="2">
<category id="3">
<category id="4" />
<category id="5" />
<category id="6" />
</category>
<category id="7" />
</category>
</category>
</rootCategories>
A...
.OrderBy(y => y.Year).ThenBy(m => m.Month);
How to set descending order?
EDIT:
I tried this:
var result = (from dn in db.DealNotes
where dn.DealID == dealID
group dn by new { month = dn.Date.Month, year = dn.Date.Year } into date
orde...
Going thru one of my favourite authors question What’s the hardest or most misunderstood aspect of LINQ? I am basically looking for the answer of the question:
How the C# compiler treats query expressions
Thanks
...
What is the easiest and somewhat efficient way to convert a flat structure:
object[][] rawData = new object[][]
{
{ "A1", "B1", "C1" },
{ "A1", "B1", "C2" },
{ "A2", "B2", "C3" },
{ "A2", "B2", "C4" }
// .. more
};
into a hierarchical structure:
class X
{
public X ()
{
Cs = new List<string>();
}
public str...
Here's my query.
var query = from g in dc.Group
join gm in dc.GroupMembers on g.ID equals gm.GroupID
where gm.UserID == UserID
select new {
id = g.ID,
name = g.Name,
pools = (from pool in g.Pool
// more stuff to populate pools
So I have...
Hi there,
Hoping this is a nice softball of a question for a friday but I have the following line of code:
//System.ArgumentOutOfRangeException generated if there is no matching data
currentAnswers = new CurrentAnswersCollection()
.Where("PARTICIPANT_ID", 10000).Load()[0];
CurrentAnswersCollection is a strongly-typed collection p...
Howdy!
So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of list I want to create will be composed of un...
if i trying to sort my columns return 0 valu. But i need max value descinding value but how?
for (int j = 0; j < dTable.Columns.Count; j++)
for (int i = 0; i < dTable.Rows.Count; i++)
{
mycounter[i] = dTable.Rows[i][j].ToString().Length;
}
mycounter = mycou...
I'd like to detemine the amount of time it takes for my ASP.Net program to generate certain sql queries using linq.... note - I want the query generation time, not the query execution time. Is this possible, or even feasable (if its usually fast)?
My website has some heavy traffic and I want to cover all of my bases.
...
Hi all,
I have a Linq query that looks something like the following
var query3 = from c in Session.CreateLinq<AccountTransaction>()
join a in Session.CreateLinq<Account>() on c.Account equals a
where c.DebitAmount >= 0
select new { a.Name, c.DebitAmount }
;
The Session object interacts with a da...
For simplicity, a "Section" object contains the following properties:
SectionId
ParentSectionId
Name
I currently have the following LINQ code to obtain child sections of a given section:
List<Section> sections = SectionCache.GetAllSections();
sections.AsQueryable().Where(s => s.ParentSectionId == 10);
This gives me all children of...
I'm interested in knowing where you have found the best, clearest and/or simplest explanation of the various technologies used in Linq, such as Lambda's, delegates etc. There are many books available on this subject, but I am looking for some source that goes into painstakingly great detail to make the subject as simple as possible.
...
I have a Batch with BatchItems entered by multiple users. I'm trying to not only get the subtotal per user for a single batch, but also grand total for that same batch regardless of the user grouping. Its this last part that I can't figure out. How might I get that total in order to return it as a list?
from b in context.BatchItem
...
I've written a code generator, that generates C# files. If the file being generated is new, I need to add a reference to it to our .csproj file. I have the following method that adds a node to a .csproj file.
private static void AddToProjectFile(string projectFileName, string projectFileEntry)
{
StreamReader streamReader = new Strea...
I have this code:
public enum MyEnum
{
First = 6,
Data1 = 6,
Data2 = 7,
Data3 = 8,
Data4 = 9,
Data5 = 10,
Last = 10,
Invalid = -1
};
Enumerable<int> _myTypes = Enumerable.Range((int)MyEnum.First, (int)MyEnum.Last);
This creates an enumerable with elements from 6 to 15. I have equivalent code starting with 1 and it works as expected. ...
Hi all,
I have a ListView setup with LinqDataSource and a button that triggers search function. To avoid display data on page_load, I set ListView's DataSourceID in the Click event of the search button, bind it and set result data in LinqDataSource's Selecting event. It works as I expected but It does't look pretty to set DataSourceId i...
I have a problem with code contracts and linq. I managed to narrow the issue to the following code sample. And now I am stuck.
public void SomeMethod()
{
var list = new List<Question>();
if (list.Take(5) == null) { }
// resharper hints that condition can never be true
if (list.ForPerson(12) == null) { }
// resharpe...
Hello,
New to LINQ and c# but having problem with one specific problem.
I have 2 Data tables.
DataTable 1 has Name, House Number in it. DataTable 2 holds Street, FirstHouseNumber, LastHouseNumber.
What I want to do is create a new table that has Name, House Number, Street in it but I keep ending up with lots of DataTable1 Count * Da...