C# or VB.NET is fine. I'd like to count number of people for each country from the following tables with LINQ to SQL I have two tables, one is Countries and other is People. It's one to many relatoionship from Countries to People. ountries table column:CountryId,CountryName People:PeopleId,FullName,CountryId (a primary key from Country table and allowed null) I want to count how many people each country has and get something like the following result that shows only the country that has people. Because there are some countries that have no people in the People table.
Basically, I am trying to write a LINQ to Objects statement where the relationship is a grandparent, parent, child relationship. (You could also call it a Master Detail relationship.)
Dim coverages As New List(Of Coverage) Dim coverage As Coverage For Each rl In oClaimsPolicy.RiskLocations
Then I want it to automatically insert data into CustomerEventType table based on the last EvenTypeID data that's just inserted and the checks of the CusID that is using CheckBoxList1 bounded from CustomerType (Suppose there are 2 IDs. )After I Click on Insert button the data in EventType table and CustomerEventType table should be:
EventType EventTypeID 1 CustomerEventType
[code]....
The only question that I have is, what should be the code behind the insert button using VB.NET LINQ-to-SQL to get this result?
I have a many to many relationship between 2 tables so therefore I have created a bridge table, to produce a one to many relationship. how to I code this, so it shows in a datagrid?
I have a table in which I populate a datagridview from. Now, I want to display certain info like Batchnumber in the first datagridview. And then in the second datagridview I want to display different data from the same table. Is it possible to have a master/detail scenario in this situation
i have problem when i generate my program the program takes time till in my datagridview from table adapter in which i already create in a dataset any way how to make the program fill the records faster and decrease the loading time when fill in the datagridview? [code]
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer where poll_nbr = 16 group by answer_nbr The LINQ to SQL query
I write the code below. I want to make short using linq count.
Dim query0 = From obj In dtAginglist _ Where (obj.Field(Of String)("CurrentStatus") = "Open" Or obj.Field(Of String)("CurrentStatus") = "Acknowledge") _
[Code]....
I try to use code below but it dosen't work with if source is datatable.
Dim orderCounts = From c In customers New With { _ c.CustomerID, Key .OrderCount = c.Orders.Count() }
I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop.
Table structures:
Employees: EmployeeId(PK) , FirstName, LastName CafeLogs: LogId (PK), CashierId, EmployeeId, Value, => CashierId and EmployeeId are the data from column EmployeeId of Empoyee table
Table relationship:
Employees 1:N CafeLogs (CashierId (FK))
[code]....
Right now I know how to select only LogId, Employee's name, and , Value, not with Cashier name yet.
Dim query = From log In db.CafeLogs _ Join emp In db.Employees On emp.EmployeeId Equals log.EmployeeId _ Select log.LogId, emp.FirsName, emp.LastName, log.Value
I am learning Linq, so bear with me. I have a class object that holds 4 other class objects with each holding a List(Of T) of the next. Think tiered classes. As these lists as built I need to search all the Group2 for all Group3 to see which Group3.units.count is the largest. "units" being a List(Of T). [code]
I'm very new to linq and I'm trying to come up with a linq query against a dataset that will return a max count value based on grouping records.[code]...
I'm trying to create a LINQ query (or queries) that count the total number of occurences of a combinations of items in one list that exist in a different list. For example, take the following lists:
The result of the query operation should be 2 since I can find two combinations of AAA and BBB (from DiscountItems) within the contents of CartItems.My thinking in approaching the query is to join the lists together to shorten CartItems to only include items from DiscountItems. The solution would be to find the CartItem in the resulting query that occurs the least amount of times, thus indicating how many combinations of items exist in CartItems.When CartItems is filtered to only the items in DiscountItems, it can be visually displayed like this:
CartItems that get a discount ============================= AAA BBB <= This combination is eligible for a discount AAA BBB <= This combination is eligible for a discount AAA <= Not eligible
Thus, because there are 2 combinations of the discount in the Cart, the result is 2.Here's the query I already have, but it's not working. query results in an enumeration with 100 items, far more than I expected.
Dim query = From cartItem In Cart.CartItems Group Join discountItem In DiscountGroup.DiscountItems
I'd take both C# and VB.NET suggestion.I'm using LINQ to query data. I'm trying to query the parent and count the child tags.Here's my Tags table column:
TagId (int primary) TagName ParentId (int Allow NULL referred to TagId column)
I have a the following Class structure. Company > List(of Departments) > List(of Employees) I want to Query a Company to find out if it has a department of the following name and a Employee in that department with the following ID! How could I query this. The way I have the code it expect to return one department so I have it doing
I have a requirement where I have to add items into a List(Of T) (let's call it Target) from an IEnumerable(Of T) (let's call it Source) using Target.AddRange() in VB.NET.
The ? part is a tricky condition that is something like: As long as the as yet unenumerated count is not equal to what is needed to fill the list to the minimum required then randomly decide if the current item should be taken, otherwise take the item.Somethig like...
Source.Count() - Index = _minimum_required - _curr_count_of_items_taken _ OrElse GetRandomNumberBetween1And100() <= _probability_this_item_is_taken ' _minimum_required and _probability_this_item_is_taken are constants
The confounding part is that _curr_count_of_items_taken needs to be incremented each time the TakeWhile statement is satisfied. How would I go about doing that? I'm also open to a solution that uses any other LINQ methods (Aggregate, Where, etc.) instead of TakeWhile.If all else fails then I will go back to using a good old for-loop =)
I have the following SQL query to return all Customers who have no OrderLines with no Parts assigned - i.e. I only want the customers within which every order line of every order has no parts assigned - (in the actual problem I am dealing with a different domain but have translated to customers/orders to illustrate the problem)
SELECT c.Customer_PK FROM Customers c INNER JOIN Orders o[code].....
This works but generates less than optimal SQL - it is doing a subquery for Count on each row of the customers query rather than using Group By and Having. I tried making the LINQ Group By syntax work but it kept putting the filter as a WHERE not a HAVING clause.Edit in response to Answers below: I am accepting JamieSee's answer as it addresses the stated problem, even though it does not produce the GROUP BY HAVING query I originally had.I am a VB developer so I have had a crack translating your code to VB, this is the closest I got to but it does not quite produce the desired output:
Dim qry = From c In context.Customers Group Join o In context.Orders On c.Customer_PK Equals o.Customer_FK Into joinedOrders = Group[cod].....
The problem I had is that I have to push "jl" into the Group By "Key" so I can reference it from the Where clause, otherwise the compiler cannot see that variable or any of the other variables appearing before the Group By clause.With the filter as specified I get all customers where at least one order has lines with no parts rather than only customers with no parts in any order.
Dim assSummary = From a In db.Assignments Join ur In db.UserRegions On a.Origin.ID Equals ur.Region.ID
[code]....
In the controller I can return the data easily as follows:
For Each c In assSummary MsgBox(c.Description & " " & c.AssCount) Next
If I pass the object through to the view using Viewdata("assSummary") = assSummary, how do I display the data? Every method I've tried results in messages about 'VB$AnonymousType_7(Of Integer,String) and I don't know how to retrieve the data from the anonymous type.
Can a LINQ or a LAMBDA expression be used to count the 1's in a binary string ?For example, if I convert a number to its BINARY using.>>
Dim binaryString As String = Convert.ToString( numberVariable, 2 )
1) Without using a loop such as a FOR NEXT loop, can I count the number of 1's in the STRING using LINQ or a LAMBDA expression?
2) Can I get the indexes of where the 1's are at in a collection such as a LIST using LINQ or a LAMBDA expression?I know the syntax of some LINQ expressions, however, I don't know which method may be suitable.
I have added an unbound column SMS in my DataGridView1 where i want to show the count of rows from another related table (History) according to the ClientID present in both the tables (ClientProfile & History). How can i do this? My present query is as follows:[code]
I have a table (Projects) which is linked to projectVersions on projectID..projectVersions contains several columns on which I'd like to filter a returned project (and associated projectVersions) list. For example there is a "capacity" column and a "country" column. I am doing a filtered list of projects on one page and I'd like to include all projects where any one of the associated projectVersions has a capacity of 750ml and a country of "France" for example.It may be that a particular parameter is not set and so I pass a zero to indicate not to filter on that.I guess this needs some kind of subquery as when I try and do something like this: [code] it doesn't work as the "xxx" bit, being one-to-many, expects me to specify an item to get at the entities within and yet I want to query where ANY of the associated versions match one of the criteria.
I'm trying to write a Function that retrieves the number of rows within a particular table on a HTML page. The table doesn't appear to have a name rather has been allocated a class called "messagelist"What I'm trying to do is have the code that will read my email messages in my web mail account andreport to me when its finished. I'm able to log on and access my inbox but are struggling from here on in.
<tr class="control"><td colspan="6"><form method="post" name="messages" action="/horde/imp/mailbox.php?nocache=asdash635"><table class="messageList" cellspacing="1"><tr class="item">I CANT SEEM TO FIND A TABLE NAME --Can I use table class?All the ROWS are coded...<tr id="row42290" class="unseen"> <td> <input id="check42290" type="checkbox" class="checkbox" name="indices[]"
I currently have the below code to list all tables in a MS Access Database, what I would like to do is alos COUNT the TOTAL records within each table and display that info in a listview control.
how to get that info.
This is the code I am currently using to get the list of tables from the database:
Dim userTables As DataTable = Nothing Dim i As Integer Dim restrictions() As String = New String(3) {}