linq

SQL to Linq equivalent

I've got this stored procedure I'd like to convert to LINQ to SQL, but I'm having a bit of trouble because I'm new to LINQ (and actually, I'm no SQL guru) and I am not getting the expected results. (I tried calling the SPROC from LINQ to SQL but when I send in the Period datetime as parameter on the SPROC I get some error on L2S about th...

Subsonic 3.0 and "Link" tables.

I have the following set-up. BlogPosts BlogToCategory Category One blog post can have many categorys and a category can be in many blog posts. (Hence the intermediate table. How would I go about getting a list of all the blog-posts in one category. I've tried this but cant seem to get it right (I get a IQueryable -> IEnumerable cast...

Property with Enumerable or list

I'm playing around with LINQ and related subjects and was wondering about the following. I've 2 methods of getting a Fibonacci sequence. I started with: public static IEnumerable<int> Fibonacci { get { int i = 0; int j = 1; int temp = 0; while (true) { ...

LINQ - problem with mapping an association

Hello, I've a table Role associated in 1-many relation with table User in my database. I've created LINQ mapping classes manually: [Table(Name="Role")] public class Role { private EntitySet<User> _Users; [Column(IsPrimaryKey = true, IsDbGenerated = true, AutoSync = AutoSync.OnInsert)] public int RoleID { get; set; } [C...

Feasibility of entity framework and linq to sql

Is it worth spending time in these frameworks. Or they just another framework like microsoft developed in the form of MFC library. I dont want to waste precious time, so please help. Under what scenarios these frameworks will be helpful. ...

IQueryable contains any of string array

I am not shore why IQuerable limits me when I try to search database for data containing string from an array. objectFactory.Resolve<IUserDao>().Query. Where(t => (spltedInput.Any(val=> t.LastName.Contains(val)) || spltedInput.Any(val=> t.Name.Contains(val))) && t.MasterCompany.I...

Linq-To-SQL Check existance of a record before returning resultset.

I'm looking for a simple solution to replace my standardized junk way of validating whether a record exists before attempting to retrieve the data. Currently, whenever one of my methods are called, I do something to the effect of... private Record DoSomething(int id) { if(data.Records.Count(q=>q.Id==id) > 0) { return data.R...

Get Non-Distinct elements from an IEnumerable

I have a class called Item. Item has an identifier property called ItemCode which is a string. I would like to get a list of all non-distinct Items in a list of Items. Example: List<Item> itemList = new List<Item>() { new Item("code1", "description1"), new Item("code2", "description2"), new Item("code2", "description3"), }; ...

Assert all in A belongs to B and all in B belongs to A

I'm rather proud to have produced this Linq assertion on my own: bool assert1 = (from e in A select B.Contains<T>(e, new TComparer())) .All(x => x == true); bool assert2 = (from e in B select A.Contains<T>(e, new TComparer())) .All(x => x == true); Assert(assert1 && assert2);...

Match elements between 2 collections with Linq in c#

Hi, i have a question about how to do a common programming task in linq. lets say we have do different collections or arrays. What i would like to do is match elements between arrays and if there is a match then do something with that element. eg: string[] collection1 = new string[] { "1", "7", "4" }; string[] collecti...

How to write simple Where Clause for dynamic filtering in linq when we use groups in join

I have simple search page i want to filter the results. var TransactionStats = from trans in context.ProductTransactionSet.Include("SPL") select new { trans.InvoiceNo, ProductGroup = from tranline in trans.ProductTransactionLines group tranline by tranline.ProductTransaction.TransactionID ...

How do I insert an element into XML using Linq?

My XML: <content> <item id="1">A</item> <item id="2">B</item> <item id="4">D</item> </content> I have loaded this using XML similar to: XDocument xDoc = new XDocument(data.Value); var items = from i in xDoc.Element("content").Elements("item") select i; I want to insert another element, to end up with something like:...

Return master rows based on detail filter

Hello I have a query where I want to return Master rows based on whether the detail fulfil a certain criteria. For example, I only want to return a particular Master row if AT LEAST one of the Detail rows have SomeProperty = X. Based on the following predicate: predicate = predicate.And(p => ...

How does Linq-to-Xml convert objects to strings?

Linq-to-Xml contains lots of methods that allow you to add arbitrary objects to an xml tree. These objects are converted to strings by some means, but I can't seem to find the specification of how this occurs. The conversion I'm referring to is mentioned (but not specified) in MSDN. I happen to need this for javascript interop, but th...

What is "Audit Logout" in SQL Server Profiler?

I'm running a data import (using C#/Linq), and naturally I'm trying to optimize my queries as much as possible. To this end I'm running a trace on the DB using SQL Server Profiler, with my trace filtered by my SQL login name (it's a name that can uniquely be attributed to my data import process). Strangely enough, most of my SQL statem...

Merging Dictionary containing a List in C#

This is kind-of related to this question, on how to merge two dictionaries in C#. An elegant Linq solution is presented, which is cool. However, that question relates to Dictionary<Object1, Object2>, whereas I have a dictionary where the value is a List<Object2>. I am looking for a solution for merging a Dictionary<Object1, List<Object...

Find minimal and maximun date in array using LINQ?

I have an array of classes with a property Date, i.e.: class Record { public DateTime Date { get; private set; } } void Summarize(Record[] arr) { foreach (var r in arr) { // do stuff } } I have to find the earliest (minimum) and the latest (maximum) dates in this array. How can I do that using LINQ? ...

db4o, Linq, and UUID's

Apparently the db4o website was recently redone, and now old urls are giving 404 errors. Everytime I think I've found the answer, I get a 404 error. I have a simple db4o database I've setup to store people. public class Person { public string Firstname { get; set;} public string Lastname {get;set;} } I've been able to run L...

List<T>.RemoveAll Doesn't Exist in Silverlight?

I'm working on a Silverlight 2/3 application. I would like to use List.RemoveAll (or maybe it's IList.RemoveAll?) and specify a predicate so that I can remove a bunch of elements from a list in one sweep. It seems like this function doesn't exist in Silverlight, though. Am I missing something here? Is there an alternative approach that'...

any free linq provider available for oracle?

I am looking for a free linq provider for oracle. I dont need advanced features. What all I need is CRUD operations + ability to generate model from oracle db. I would like to use this on production web site(using ASP.NET & Silverlight). Any pointers & suggestions will be appreciated. ...