linq

LINQ to Java?

I'm looking for something simlar to linq except for java? any suggestions of where to go? ...

Optimizing a LINQ to SQL query.

I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount) { DatabaseDataContext db = new DatabaseDataContext(); return (from o in db.Orders orderby o.CreatedDate descending select o) .Skip(pageIndex * recordCount) .Take(recordCount) .ToList(); } I need to print the infor...

Dynamic linq:Creating an extension method that produces JSON result

I'm stuck trying to create a dynamic linq extension method that returns a string in JSON format - I'm using System.Linq.Dynamic and Newtonsoft.Json and I can't get the Linq.Dynamic to parse the "cell=new object[]" part. Perhaps too complex? Any ideas? : static void Main(string[] args) { NorthwindDataContext db = new Nort...

linq - how do you do a query for items in one query source that are not in another one?

If I have 2 query sources how do I find ones that are in one that are not in the other? example of join to find items in both: var results = from item1 in qs1.Items join item2 in qs2 on item1.field1 equals item2.field2 select item1; So what would the linq code be to return the items in qs1 that are not in qs2? ...

Seperating concerns with Linq To SQL and DTO's

I recently started a new webforms project and decided to seperate the business classes from any DBML references. My business layer classes instead access discrete Data layer methods and are returned collections of DTO's. So the data layer might project DTO's like the following: (from c in dataContext.Customers where c.Active == true se...

How can you handle an IN sub-query with LINQ to SQL?

I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL: SELECT f.* FROM Foo f WHERE f.FooId IN ( SELECT fb.FooId FROM FooBar fb WHERE fb.BarId = 1000 ) Any help would be gratefully received. Thanks. ...

How are people unit testing code that uses Linq to SQL

How are people unit testing code that uses Linq to SQL? ...

NHibernate or LINQ to SQL

If starting a new project what would you use for your ORM NHibernate or LINQ and why. What are the pros and cons of each. edit: LINQ to SQL not just LINQ (thanks @Jon Limjap) ...

How do I compose existing Linq Expressions

I want to compose the results of two Linq Expressions. They exist in the form Expression<Func<T, bool>> So the two that I want to compose are essentially delegates on a parameter (of type T) that both return a boolean. The result I would like composed would be the logical evaluation of the booleans. I would probably implement it as an...

Linq to SQL - Accessing System Databases/Tables?

Right now I have an SSIS package that runs every morning and gives me a report on the number of packages that failed or succeeded from the day before. The information for these packages is contained partly within the sysjobs table (a system table) within the msdb database (a system database) in SQL Server 2005. When trying to move the ...

How would you refactor this LINQ code?

I've got a lot of ugly code that looks like this: if (!string.IsNullOrEmpty(ddlFileName.SelectedItem.Text)) results = results.Where(x => x.FileName.Contains(ddlFileName.SelectedValue)); if (chkFileName.Checked) results = results.Where(x => x.FileName == null); if (!string.IsNullOrEmpty(ddlIPAddress.SelectedItem.Text)) resul...

Using Linq, how can I pass a var back from a method?

I have a Linq query that I want to call from multiple places: var myData = from a in db.MyTable where a.MyValue == "A" select new { a.Key, a.MyValue }; How can I create a method, put this code in it, and then call it? public ??? GetSomeData() { // my Linq query } ...

How can I test that my Linq IQueryable has executed

I am currently using Linq to NHibernate (although that is not an issue with regards to this question) to execute queries against my database and I want to be able to test whether the current IQueryable result instance has been executed or not. The debugger knows that my IQueryable has not been 'invoked' because it tells me that expandin...

How do you perform a CROSS JOIN with LINQ to SQL?

How do you perform a CROSS JOIN with LINQ to SQL? ...

What's the best way to handle one-to-one relationships in SQL?

Let's say I've got Alpha things that may or may not be or be related to Bravo or Charlie things. These are one-to-one relationships: No Alpha will relate to more than one Bravo. And no Bravo will relate to more than one Alpha. I've got a few goals: a system that's easy to learn and maintain. data integrity enforced within my databas...

bug in linq Contains statement - is there a fix or workaround?

I found a bug in the Contains statement in Linq (not sure if it is really in Linq or Linq to SQL) and want to know if anyone else has seen this and if there is a fix or workaround. If the querysource you do the contains with has more than 10 items in it, it does not pass the items correctly to the SQL query. It is hard to explain what i...

Linq to NHibernate multiple OrderBy calls

I'm having trouble ordering by more than one field in my Linq to NHibernate query. Does anyone either know what might be wrong or if there is a work around? Thanks! Rob Code: IQueryable<AgendaItem> items = _agendaRepository.GetAgendaItems(location) .Where(item => item.Minutes.Contains(query) || item.Description.Contains(query)); ...

ASP.NET Convert Invalid String to Null

In my application I have TextBox in a FormView bound to a LinqDataSource like so: <asp:TextBox ID="MyTextBox" runat="server" Text='<%# Bind("MyValue") %>' AutoPostBack="True" ontextchanged="MyTextBox_TextChanged" /> protected void MyTextBox_TextChanged(object sender, EventArgs e) { MyFormView.UpdateItem(...

Empty namespace using Linq Xml

I'm trying to create a sitemap using Linq to Xml, but am getting an empty namespace attribute, which I would like to get rid of. e.g. XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new XElement(ns + "urlset", new XElement("url", ne...

Sum of items in a collection

Using LINQ to SQL, I have an Order class with a collection of OrderDetails. The Order Details has a property called LineTotal which gets Qnty x ItemPrice. I know how to do a new LINQ query of the database to find the order total, but as I already have the collection of OrderDetails from the DB, is there a simple method to return the s...