linq

Looking for method to tell the difference between to strings

Hello folks, I was wondering if there are any free implementations of a string compare, that tells the difference between two multiline strings. I'm lookin for something like the compare screen of Microsoft SourceSafe. What I want to achieve is, is to compare two html websites and get an overview of the changes. (The use case will be i...

Does deleting from a LINQ DB also delete records in other tables that have a foreign key association?

So at the root of my DB, I have a table "Customer." Customer has foreign keys going to about 6-7 other tables such as Receipts, Addresses, Documents etc. If I were to delete a customer using SubmitChanges(), would that seek out all those records with the foreign key association and delete them too, or would I need to do like 6 queries? ...

Get a list of distinct items and their count

I have an object, that has many properties but the only two to worry about are: myobject.ID which is an int myobject.Names which is a HashSet Then I have a List of those objects that looks something similar to this: List<myobject> I use Linq to get a some of the data into a repeater, but I'm not sure how to get the list of Names and...

getting strongly typed column names from datacontext

Is it possible to get the column names directly from a datacontext? Below I'm just hard coding the DataTextField and DataValueField, but I'd like to be able to get them from the datacontext if possible. What is the recommended way of getting the column names in a strongly-typed way? DataClassesDataContext db = new DataClassesDataContext...

Linq to XML - Adding an Element

I am trying to add and delete elements from a C# .csproj file. The file, in part, appears below. Can someone show me how I can do the following two things? 1) Add an element as shown below (the line that says, "I want to add this") 2) Delete an element. For example, say I wanted to delete the line I have indicated below. <?xml version...

Linq To Sql - Dynamic OrderBy - Case When

Hello, I'm using Linq to sql and Linq Dynamic OrderBy. I know linq dynamic can do simple sorting like - orderby("column_name"). But does it support something more complex like queries with "CASE WHEN" in them ? string orderbyQuery = "(CASE WHEN (username == 100) THEN 1 ELSE 0 END) DESC)"; here is my query : var u = from u in db.us...

Why use .AsEnumerable() rather than casting to IEnumerable<T>?

One of the extension methods on IEnumerable<T> is .AsEnumerable(). This method converts the enumerable object it was called on into an instance of IEnumerable<T>. However, since an object must implement IEnumerable<T> in order to apply to this extension method, converting to IEnumerable<T> is a simple matter of casting to IEnumerable<T>....

Updating linq to sql object causing System.NotSupportedException: An attempt has been made to Attach or Add an entity that is not new perhaps having been loaded from another DataContext.

I get the above System.NotSupportedException when I want to update an object's with child entities. The scenario is like this: I have a SubscriberProvider that allows me to create subscribers. var provider = new SubscriberProvider(); // Creates a new repository with own datacontext var newSubscriber = new Subscriber { EmailAddress...

LinqToSql with dates problem

Hi, I have a simple LinqToSql query from p in GL_PROJECTs where p.CREATE_DT == new DateTime(2009,10,26) select new p Some of the records in the database have create dates with time parts other than 00:00:00, so wont be retreived by this query. What I want to achieve is a time insensitive retrieval for the whole day. I tried the fol...

How would I use LINQ to XML to get the value from example XML

Here is the xml I am trying to access: <resourceStrings> <globalStrings> <string> <key>RptTitle1</key> <value>Title1</value> </string> <string> <key>RptTitle2</key> <value>ReportTitle2</value> </string> <string> ...

How can I load the following XML using LINQ-to-XML into a dictionary?

How can I load the following formatted XML document: <Settings> <MimeTypes> <MimeType Type="application/mac-binhex40" Extensions=".hqx"/> <MimeType Type="application/msword" Extensions=".doc;.docx"/> <MimeType Type="application/pdf" Extensions=".pdf"/> <MimeType Type="application/vnd.ms-excel" Extensi...

How to use Linq and the IN clause

Here is my code if (catid != 0) posts = posts.Where(x => x.catid IN '1,8,2,109,23'); The in in this code shows as a syntax error. Is there a way to fix this ...

C# Connecting to mysql using linq VS OleDB

Hi, I'm developing a web application with ASP.net & C# and it needs to connect to mysql database. I'm not sure if I should use linq or OleDB to connect to mysql!!! can you give me some advices about that? ...

Is StringComparer.CurrentCulture the right choice to use in this case?

I have a list of UTF-8 strings that I want to sort using Enumerable.OrderBy. The strings may contain any number of character sets - e.g., English, German, and Japanese, or a mix of them, even. For example, here is a sample input list: ["東京","North 東京", "München", "New York", "Chicago", "大阪市"] I am confused as to whether using String...

WCF, LINQ, Silverlight Problem

I am starting to learn silverlight, WCF and LINQ here. the silverlight is hosted in the asp.net website. in the asp.net website, 1. added LINQ to SQL Classes with one table "ABC". 2. added WCF Service with one method "RetrieveABC" to retrieve "ABC" table from database. 3. in Silverlight Added WCF Service and successfully run RetrieveAB...

Databind a List with a Template to a Dropdown Datasource

I have a Template via: public class OwnedProvinces { public Guid ProvinceID; public string ProvinceName; } And I created a list with this template here: List<OwnedProvinces> getinfo = (from upi in db.Utopia_Province_Data_Captured_Gens where upi.Owner_User_ID == SQLStatementsCS.UserID(...

Odd Lambda Expression Question

List<string> a = new List<string>() { "a", "b", "c" }; List<string> b = new List<string>() { "a", "b", "c", "d", "e", "f" }; b.RemoveAll(a.Contains); If you loop through b it will now only contain d e and f. Can anyone expand out whats actually happening, because currently it doesnt make any sense at all. Edit: I was more talking abo...

linq-to-sql is this the most efficient code review

hey all. Just wanting to know is this the most efficient way of getting values from a db: given; ----------- --------------- ------------- | Channel | |Issue | |Topic | | path(ck)| |channelID(fk)| |issueID(fk)| ----------- --------------- ------------- One channel has many Issues One Issue has man...

Custom MembershipProvider with Web interface and DAL

Hi, I'm working on an ASP.NET solution with 2 projects. One is the web interface and the other contains my business logic. I'm using LINQ to SQL for my data access in the second project. Apart of my database, I have a table called Users which holds user information. I've started to implement a MembershipProvider. I notice that Members...

How to write this query as lambda expression?

I'm still having problems to write lambda expressions that should create some object and to set properties with the object initializer. How would this query be written as a lambda expression? List<CategoryContainer> _catList = (from q in _dc.Category select new CategoryContainer ...