string[] filesOfType1 = GetFileList1();
string[] filesOfType2 = GetFileList2();
var cookieMap = new Dictionary<string, CookieContainer>();
Action<string, Func<string, KeyValuePair<string, CookieContainer>>> addToMap = (filename, pairGetter) =>
{
KeyValuePair<string, CookieContainer> cookiePair;
try
{
cookiePair = pairGetter(fi...
I want to convert an XML document containing many elements within a node (around 150) into another XML document with a slightly different schema but mostly with the same element names. Now do I have to manually map each element/node between the 2 documents. For that I will have to hardcode 150 lines of mapping and element names. Somethin...
For example for the following XML
<Order>
<Phone>1254</Phone>
<City>City1</City>
<State>State</State>
</Order>
I might want to find out whether the XElement contains "City" Node or not.
...
Hi hope some one can help. I have an ASP .Net (3.5) website. I have the following code that uploads a file as a binary to a SQL Database:
Print("
protected void UploadButton_Click(object sender, EventArgs e)
{
//Get the posted file
Stream fileDataStream = FileUpload.PostedFile.InputStream;
...
As title. I didn't find one via google, at any rate.
Update: thanks for the links from the two answers; this is very useful, but not what I was after - I am curious to see whether it is possible to query an IRepository backed by memcached (or some other distributed cache), backed by a RDBMS. I've really no idea how that might work in ...
I am designing a simple internal framework for handling time series data.
Given that LINQ is my current toy hammer, I want to hit everything with it.
I want to implement methods in class TimeSeries (Select(), Where() and so on) so that I can use LINQ syntax to handle time series data
Some things are straight forward, e.g. (from x in A ...
I am playing with the new stuff of C#3.0 and I have this code (mostly taken from MSDN) but I can only get true,false,true... and not the real value :
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var oddNumbers = numbers.Select(n => n % 2 == 1);
Console.WriteLine("Numbers < 5:");
foreach (var x in o...
I am digging into LINQ--trying to understand basic models (it seems pretty cool to me). The code below is the code to perform before committing an update.
Linq01.Account acc = context.Accounts.Single( pc => pc.AccountID == AccountID );
acc.Name = textboxAccountNameRead.Text.Trim();
context.SubmitChanges();
So far, so good....
So I have this large XML file containing 300+ elements for each record and I need to insert these records into a database table. The name of the nodes in the XML file are the same as the column names in the db. And they're all strings. Is there an automatic way to map them and insert the data or will I have to write out lines of code map...
Hi, I have 3 classes
public class Item
{
...
}
public class Order
{
public List Items
...
}
public class Customer
{
public List Orders
...
}
Now, using LINQ I need to get all items that a customer bought. How can I?
I tried something like var items = from o in cust.Orders select o.Items; but result is IEnuberable> and I wanna just one...
How do I properly convert two columns from SQL (2008) using Linq into a Dictionary (for caching)?
I currently loop through the IQueryable b/c I can't get the ToDictionary method to work. Any ideas?
This works:
var query = from p in db.Table
select p;
Dictionary<string, string> dic = new Dictionary<string, string>();
forea...
If I have the following string:
string s = "abcdefghab";
Then how do I get a string (or char[]) that has just the characters that are repeated in the original string using C# and LINQ. In my example I want to end up with "ab".
Although not necessary, I was trying to do this in a single line of LINQ and had so far come up with:
s.ToC...
I have recently had the need to write a fluent interface for C# that will essentially mirror SQL. Yes, I am aware of LINQ to SQL, but I'm interesting in getting "closer to the metal"--having something that essentially provides nothing more than an Intellisensified SQL shim within C#.
E.g.,
var fq = new FluentQuery();
Expression<Action...
We are using LINQ very widely in our system. Particularly LINQ-to-objects. So in some places we end up having a LINQ query in memory build up from some huge expressions. The problem comes when there's some bug in the expressions. So we get NullReferenceException and the stack trace leads us nowhere (to [Lightweight Function]). The except...
On a recent Dot Net Rocks podcast, Jon Skeet mentioned possible abuses of LINQ syntax. What examples have people seen where crazy things are being done with LINQ?
...
In my application I keep a LINQ object fetched from the database, and regularly modifies it followed by db.SubmitChanges().
I have read that you are not supposed to keep around the DataContext object for a long time.
But if I close my DataContext between modifications, I guess the data object loses its link to the actual database row.
...
I have a BindingSource control (http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx) with a datasource of a (single) Linq object. If I change any of the properties of the underlying Linq-to-Sql object then all the other changes on the bound controls on the form are lost.
Does anyone now why and how I work ar...
I am using T4 to generate some screens and middle-tier code for a project, and would like to use Linq to simplify some of my template code. However, when I try to use Linq, the template reports a syntax error.
...
// goal: update Address record identified by "id", with new data in "colVal"
string cstr = ConnectionApi.GetSqlConnectionString("SwDb"); // get connection str
using (DataContext db = new DataContext(cstr)) {
Address addr = (from a in db.GetTable<Address>()
where a.Id == id
select a).Single<Add...
Hi,
We need to generate LINQ queries which are 100% unknown during coding (design time). This is because the logic is available in our framework which is 100% separated from any data projects. For data we use LLBLGen generated data access code.
Normally by using invokes on the DLL, which we specify to the framework (not reference) we c...