LINQ multiple childs in 1 row
My tables are structured as below: Questions id title 1 what is this? Answers id answer qid 1 an 1 I want to select the question and all the answers in one single row through LINQ? How can i do this? ...
My tables are structured as below: Questions id title 1 what is this? Answers id answer qid 1 an 1 I want to select the question and all the answers in one single row through LINQ? How can i do this? ...
I have a list of news unsorted items, some of which have a priority flag. I need the priority items to float to the top of the list, and then sort the rest by a date. So, the end result is a list of news items that has the priority items showing at the top and the remainder sorted by date. There has to be a better way to do it than th...
I am trying to join two objects, the first is a (static) local object defined in a Helper and the second (Subsonic) Database object. Here is the offending extract from my repository, I wont bore you with the models and helpers unless requested. public IQueryable GetData(string DataType) { IQueryable<DatabaseObject> dat...
I'm fighting with linq trying to learn the syntax and I can't figure out how to do the following simple query SELECT DISTINCT user.firstname, user.lastname, COUNT(invoice.amount), SUM(invoice.amount) FROM company_user INNER JOIN user ON company_user.user_id = user.user_id INNER JOIN ...
I would like to flatten a collection of DTO's into a single DO using LINQ, but my LINQ-fu is weak. My DTO looks like this: public class DTO { Product product, Location location, MonthPeriod month, double Data } and maps to a SQL database table with this schema: ProductID int, LocationID int, MonthPeriodID int, Data numer...
Hi all, I recently shifted from JAVA development environment to .net development environment. I am developing web application using .net MVC framework. Would someone help me to find the meaning of following code segment. It seams like iterating thought list, but I could not find specific definition of this code sample: SmartTextBoxMod...
The following LINQ to NHibernate (using NHibernate 3.0) results in a System.InvalidOperationException being thrown with the message "The binary operator Equal is not defined for the types 'System.Collections.Generic.IList`1[System.Int32]' and 'System.Int32'" public IEnumerable<ProjectSummary> GetProjects( IList<int> clients ) { usin...
Could this Oracle query:select * from table(some_stored_procedure(someParameter => :someValue) be transformed into LINQ? ...
I am using the Entity framework for the first time, and would like to know if I am using in the best practice. I have created a sperate class in my business logic which will handle the entity context. the problem I have, is in all the videos I have seen they usually wrap the context in a using statement to make sure its closed, but ob...
I found a method to shuffle an array on the internet. Random rand = new Random(); shuffledArray = myArray.OrderBy(x => rand.Next()).ToArray(); However, I am a little concerned about the correctness of this method. If OrderBy executes x => rand.Next() many times for the same item, the results may conflict and result in weird things (po...
i have a linq query that returns Articles ordered by the number of tags that match the current article e.g current article has tags - tag1, tag2, tag3 tagged article 1 - tag1,tag2,tag3 tagged article 2 - tag1,tag2 linq i have is DataTable query = (from row in dt.AsEnumerable() let tags = row.Field<str...
I've got a dictionary laid out like so: Dictionary<string, List<Series>> example = new Dictionary<string, List<Series>>(); example.Add("Meter1",new List<Series>(){ new Series{ name="Usage", data = new double[] {1,2,3}}, new Series{ name = "Demand", data= new double[]{4,5,6}}}); example.Add("Meter2", new Lis...
Hi all, I am trying to transform a string made of words starting with an uppercase letter. I want to separate each word with a space and keep only the first uppercase letter. All other letters should be lowercase. For example, "TheQuickBrownFox" would become "The quick brown fox". Obviously, I could use a simple foreach and build a st...
I'm having a heckuva time figuring out how to translate a simple SQL LEFT OUTER JOIN with a two condition where clause into a working Linq-to-Entities query. There are only two tables. I need values for all rows from Table1, regardless of matches in Table2, but the WHERE clause uses fields from Table2. In SQL, the two parameters would...
I am very new to MVC and LINQ.And have some questions. I have a table named users where I am storing "M" or "F" for male and female.There is another table called Genders Which is linked to the Users table.I have Users Model in ASP.NET MVC application.My question is when I show data where should I create a property to convert that "M" to...
I have basically to select all employee from companies which are being passed so a variable - CompanyListIds - Contains list of all company ids.. var result=DataContext.Employee(e=>e.CompanyId==companyId).ToList(); The above is a query I have for selecting from one company, now how would I modify it to compare with all the companyi...
I have a simple requirement to be implemented on a silverlight app. I want to list down all the stored procs in a drop down and view its output on a grid. I am currently having a linq to sql class where I have drag dropped all the stored procs I want to view and generated the classes on a .dbml file. This works for me at the moment. Howe...
I have an EntityFramework model that has User entity that has an EntityCollection of Organisations. For a particular User I am trying to write a Linq Query to return the names of the organisations that the user belongs where that query will hit the db only once. My problem is that I cannot see how to write this query without having to ...
Up to now, when doing join operation in LINQ, I have no idea how to decide which list must come first and which list must come after. Assume I have two list, List<Product> and List<Order>. Edit: My confusion is to decide List<Product>.Join(List<Order>, ...) or List<Order>.Join(List<Product>, ...) ? ...
My particular example is fairly complex but I think the concept would apply equally to something like a logging system so I'll use that instead for ease of explanation. It's a ficticious example, please don't harp on or agonise over what is achitectually, programatically or morally wrong with the example itself :) Say you have this: cl...