linq

Username/Password Database Checking

How can I improve this username/password checking? [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(FormCollection collection) { var users = (from p in _dataContext.Users where p.Name == collection["Username"] && p.Password == collection["Password"] select p); if (...

XDocument producing invalid XML

I have this code Dim doc As XDocument = New XDocument( _ New XDeclaration("1.0", "utf-8", "yes"), _ New XElement("transaction", _ New XElement("realm", wcRealm), _ New XElement("password", wcPassword), _ New XElement("confirmation_email", wcConfEmail), _ New XElement("force_subscribe", wcSubscribe), _ New XElem...

Linq over datatable using dynamic library sample?

I am looking for sample linq code snippet which uses System.Linq.Dynamic against a datatable. Dim entities = (From ent In dt.AsEnumerable().Where(String.Format("IsUSFederal == {0}", "true")) _ Select Description = ent("Description"), Acronym = ent("Acronym")).ToList I am getting an error "there is no accessible Where can be called wit...

Linq-to-NHibernate OrderBy Not Working

I'm trying order a Linq to NHibernate query by the sum of it's children. session.Linq<Parent>().OrderBy( p => p.Children.Sum( c => c.SomeNumber ) ).ToList() This does not seem to work. When looking at NHProf, I can see that it is ordering by Parent.Id. I figured that maybe it was returning the results and ordering them outside of SQL,...

How to do a custom compare for every item in a intersect of two collections

If I have: IEnumerable<CrewBase> crewBasesLeft; IEnumerable<CrewBase> crewBasesRight; and do: IEnumerable<CrewBase> intersect = crewBasesLeft .Intersect( crewBasesRight,CrewBaseComparer.OnId() ); How do I get: CrewBase left; CrewBase right; from the: intersect so I can loop over all the CrewBases in the Intersect and make a c...

What's the difference between xelement.load and xdocument.load?

as stated above, whats the difference between XElemen.load and XDocument.load? they both load xml files... ...

Select All columns for all tables in join + linq join

How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*, CTRL_DATA_STREAM.* from CTRL_RUN_JOB inner join CTRL_DATA_STREAM on CTRL_RUN_JOB.DATA_STREAM_ID= CTRL_DATA_STREAM.DATA_STREAM_ID Linq: from CTLJCRJOB in CTRL_RUN_JOBs join CTLRFDSTM in CTRL_DATA_STREAMs on CTLJCRJOB.DATA_STREAM_ID equals ...

C# in operator-overloading

Hi, I just had an idea last nigth when writing an if-expression and sometimes the expression tend to be long when you have it like this: if(x == 1 || x == 2 || x == 33 || x == 4 || x == -5 || x == 61) { ... } x can be enums,strings,ints,chars you get the picture. I want to know if there are an easier way of writing this. I think of ...

What's the difference between multiple where clauses and && operator in LINQ-to-SQL?

It looks like I can write a where x.a==1 && x.b==1 as where x.a==1 where x.b==1 As I understand the latter turns into .Where(x => x.a == 1).Where(x => x.b ==1), but how does this translate to DB? Which would be better in terms of optimization? I can always look at the executed query from profiler but that would hardly be a generaliza...

LINQ : Determine if two sequences contains exactly the same elements

I need to determine whether or not two sets contains exactly the same elements. The ordering does not matter. For instance, these two arrays should be considered equal: IEnumerable<int> data = new []{ 3,5,6,9 }; IEnumerable<int> otherData = new []{ 6,5,9,3} One set cannot contain any elements, that are not in the other. Can this be...

LinQ to SQL : InvalidOperationException in a Windows Service

Hi all, I have implemented a small Windows Service which runs every 9 minutes and writes the data which comes througth a webservice to the db. Do do the db work I use Linq To SQL using (var db = new DataClasses1DataContext()) { var currentWeather = this.GetWeatherData(); //////TODO Add the ...

Access nested properties with dynamic lambda using Linq.Expression

Let's assume that I have two classes: class person { int ID string name Address address } class address { int ID string street string country } These classes are more or less given, they are mapped via nHibernate to be honest :) In a grid (datatables.net as base) I would like to have a type-independent sorting...

linq aggregation

Say I have classes like: public class ServiceCall { public int ServiceCallID {get; set;} public DateTime ReportedTimestamp {get; set;} public bool IsPaid {get; set;} public decimal LabourNet { get; set;} public decimal LabourVat {get; set;} } public class UsedPart { p...

Intersection of multiple lists with IEnumerable.Intersect()

Hi, I have a list of lists which I want to find the intersection for like this: var list1 = new List<int>() { 1, 2, 3 }; var list2 = new List<int>() { 2, 3, 4 }; var list3 = new List<int>() { 3, 4, 5 }; var listOfLists = new List<List<int>>() { list1, list2, list3 }; // expected intersection is List<int>() { 3 }; Is there some way to...

Convert SQLite DB files to "LINQ to SQL" like SQLMetal.exe

How do I convert SQLite DB files to LINQ ORM files? Is there any utility like SQLMetal.exe? ...

Why does .Equals not work in this LINQ example?

Why does this yield an empty set? Object[] types = {23, 234, "hello", "test", true, 23}; var newTypes = types.Select(x => x.GetType().Name) .Where(x => x.GetType().Name.Equals("Int32")) .OrderBy(x => x); newTypes.Dump(); ...

Simple sort verification for unit testing an ORDER BY?

I'm working on a DAL method that uses an ORDER BY clause in a SELECT. The return value from the method is an IEnumerable<T>, where T is a class that encapsulates a domain entity, and the sort order would be based on one of the properties of this class, namely, "Priority." It's important that this ORDER BY works, of course, so I want to...

Persistence of deferred execution linq expressions

We're trying to serialize some data, and one of the items in a collection is a "deferred execution linq statement" (actually it's the result of a Concat call on a collection). The problem is how to persist that object. It doesn't support ISerializable. The actual type is something along the lines of System.Linq.Enumerable.WhereSelectLi...

LINQ (to Entities) - Filtering items using ints

Using LINQ to Entities, how can I determine if any item from a List of ints exists in a comma delimited string of ints? For example, I want to write something like the following (logically): collection.Where(collection.DelimitedStringOfInts.Contains(listOfInts.AnyOfThem)) Also, I should mention that I'm doing this using LINQ metho...

Text manipulation

I have a malformed tab delimited csv file Name AA BB CC AA BB CC XX5 2 7 8b YY4 2 6 2 ZZ3 8 21 9 RR2 1 2 6 SS1 6 7 23 It should be like this Name AA BB CC XX5 2 7 8b YY4 2 6 2 ZZ3 8 21 9 RR2 1 2 6 SS1 6 7 23 I can't do this manually because there are way to...