Linq-to-Entities Aggregate A Column That Is Calculated In An External Function?
Feb 21, 2011
I want to Sum of the calculated column Red which is calculated in the Function IsRed() that return an integer.When I run the query I get the following error: Method 'Int32 IsRed(Int32)' has no supported translation to SQL.How should I rewrite this to get it to work.
[Code]...
View 2 Replies
ADVERTISEMENT
Feb 20, 2011
how to change this Linq to Entities (VB.Net) query to Group by L2_ID column and aggregate the calculated column diff as Sum for the group.
[Code]...
View 1 Replies
Nov 1, 2011
I want to get the average of this query.
From d In (From c In location.Descendants("temperature")
Where c.Attribute("type").Value = "hourly" Select c).Descendants("value")
Take 3
Select d
I can see the aggregate keyword in the autocomplete dropdown, but how to apply it.
View 2 Replies
Apr 20, 2011
I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:
Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....
Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:
For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....
View 1 Replies
Apr 6, 2011
I've seen the operator Max used two different ways. The following two queries produce the same results. The MSIL code is slightly different. What is the benefit of using the Aggregate operator? Logically, is there a difference?
[Code]...
View 3 Replies
May 4, 2012
[code]The LINQ query going into "result" is incomplete because I'm stumped at what is happening there. I expect FirstOrDefault to refer to refer to a single Child object at that point in the expression, but it refers to a collection of child objects. Why? What is the best way to get a list of parents that have no associated child or have a child fitting a particular condition? (My actual code will have one child max, so this sample code is not representative.)I just don't understand what the collection of FirstOrDefault could be referring to. It should really be just 1 value or nothing at all times.
View 1 Replies
May 24, 2011
To have a function that takes the average (which is calculated by a different function) say for example the average is 6, now the function is to take the number 6 and get the variance from six to another number lets say its 12 so this will return a calculation of 50% variance. now here comes the issue, i have it calculating the variance how ever lets say that there is a score that is 0, how can i make it calculate the variance without taking count for that 0? i guess you can say i need it to "skip" if its a 0.
View 5 Replies
May 24, 2010
I'm having trouble getting my head around converting a traditional SQL aggregate query into a LINQ one. The basic data dump works like so:
Dim result =
(From i As Models.InvoiceDetail In Data.InvoiceDetails.GetAll
Join ih As Models.InvoiceHeader In Data.InvoiceHeaders.GetAll On i.InvoiceHeaderID Equals ih.ID
[CODE].....................
What I need to really be getting out is ih.Period (a value from 1 to 12) and a corresponding aggregate value for i.ExtendedValue. When I try to Group ih I get errors about i being out of scope/context.
View 1 Replies
Aug 6, 2010
Given a table like
ID | Name | City
1 | X | Y
2 | Z | Y
[code].....
View 2 Replies
Aug 3, 2011
also i have a table called Orders with several columns, they contain information about the order and store the ID of the Customer they belong to.Question is: how can i query that table with (preferably) linq (the datacontext is from LinqToSql) to return the following dataI want to search for any entry with the matching CustomerID which took place, group them by Year, Sum the Totals respectively and add them to the listview?I now i could use lamda expressions and aggregate, its just not clear how (option infer on,db is a datacontext object,CustomerID is an int32 variable):
Dim Orders = (From order In db.Orders Where order.CustomerID = CustomerID).GroupBy(Function(p) p.Date.Year).GetEnumerator
I reckon i'd have to create an anonymous type like the following:
[code].....
View 1 Replies
Feb 28, 2012
The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.
Here's what I have:
<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)
[code]....
I want my usage to look something like this:
Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)
I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.
View 2 Replies
May 9, 2010
1.print the cars which are fast moving cars.
i have written this code but it shows message Cannot have aggregate function in expression[code]...
View 7 Replies
Jul 2, 2009
I am trying to aggregate a column in a datagridview. I know how to get it to work if I bind a database to it, I have several of them working perfectly, but I have one datagrid that is not bound to a database and for the life of me can not fiqure out
View 4 Replies
Feb 2, 2010
I am attempting to develop a Gradebook that one can use to modify grades and have an average calculated at the end.When you first open the form, you see the database fields in the DataGrid (socSecNumber, firstExam, secondExam, finalExam)I have a button to save the changes made here. The exam grades are null in the database.This seems to work fine, however I have a problem with the calculated column I want to add. I want it to display the socSecNumber and the average for that student. Instead, I get all four fields in addition to the semAverage field. Also, all the grades come up 250 if I fill all the fields in with 100.[code]
View 2 Replies
Apr 23, 2009
Given two tables, customer and orders, how would one do a linq query to entities to find any customers with open invoices started before a certain date?
View 1 Replies
Apr 7, 2011
This code works if I take out
" " + p.MIDDLE_NAME
Thus the remaining code looks like:
p.FIRST_NAME + " " + p.LAST_NAME
Maybe LINQ-to-Entities just doesn't support concatenating more than two strings at a time?
Protected Sub btnFilter_Click(sender As Object, e As EventArgs) Handles btnFilter.Click
Dim dbContext As Campus6Entities = New Campus6Entities
[Code]....
View 1 Replies
Feb 12, 2010
I have seen other similar questions dealing with WPF Almost exactly the same but I can;tfigure this out in ASP.net. I have a Pages table with a parentpage foreign key and want to databind them to a treeview. In the past I have created a hierarchicaldataset from a dataset but would like to stay within the entities framework if I can
View 1 Replies
Dec 11, 2010
the query below throws a System.NotSupportedException: "Unable to cast the type 'System.Linq.IOrderedQueryable1' to type 'System.Linq.IQueryable1'. LINQ to Entities only supports casting Entity Data Model primitive types." The exception is only raised in the VB.Net version. When translated to C#, no exception is raised.
Dim doesThisCrash = From outerOrder In orders
Where outerOrder.ProductId =
(From p In products Join o In orders On p.Id Equals o.ProductId
[Code]....
View 4 Replies
Sep 14, 2011
I am using LINQ with Entity Framework, and I need to get the SQL server timeCan anyone tell me how can I create a method so it retrieves the current server time?
View 1 Replies
Mar 21, 2009
I'm a bit of a n0ob to all this and I'm having trouble finding good resources on the net.What I'm trying to do is define a one-to-many relationship between two entities. I'm using the GUI tool in Visual Studio - and have created the tables in Microsoft SQL Server Management Studio.Basically, I have two tables....a 'Users' table and a 'Sites' table. A single user can have many sites associated with it.Users has a primary key of 'UID' and the Sites table as a primary key of 'Site_ID'.Sites also has a column 'UID' that should indicate which user that site is associated with.Anyway - it sounded pretty simple; but no matter what I attempt to do, I can't seem to get it to work. Mostly, I get validation errors - sometimes run-time errors, or sometimes, no actual data even though there should sites that match the UID of the user.I am able to connect and write LINQ against my Users table/pull down User objects - but can't seem to get it to know that the Sites are associated with the user.In the GUI - if I go to 'Add Association' and create a 1 to many link between Accounts and Sites - and Validate - I get an error saying, "Error1Error 11008: Association 'AccountsSites' is not mapped."
It seems like, when I try to make an association, it wants to link the 'Keys' of each entity.But U_ID and SITE_ID are the keys and, obviously, shouldn't match.If I click on the line it created in the GUI and I go to 'Table Mapping' I can see that it is trying to match those keys. Since I want it to match user_ids my first thought is to just make the U_ID the entity Key in the Sites entity but, of course, that's wrong because it would no longer allow a 1 to many relationship.
View 1 Replies
Oct 13, 2011
Basically I have the follwing:Dim ctx As New AdminCoreEntities Dim roles = (From r In ctx.Roles where r.Name.StartsWith("cust") Select r) 'list of System .Linq.IQueryable(Of AdminCoreModel.Role)
[code]...
The error i get when i run this is: Unable to cast object of type System.Data.Objects.ObjectQuery`1[AdminCoreModel.Role] to type AdminCoreModel.Role
Basically I have a many to many situation and I try to get all the Quicklinks objects queried by their roles and not quite sure why EF will cast to a single AdminCoreModel.Role when i.Roles is a collections of objects.
View 1 Replies
Nov 2, 2011
I am trying to write a query for an existing database, I am using LINQ on EF3.5 inside VS2008 as that is the only environment available to me.I have a starter query that gives me a list of items so the user can select what they want.
"e.Result =
From c In MLDb.TBL_FeatureInfoSet
Order By c.INSP_ROUTINE_NM
Select c.INSP_ROUTINE_NM
Distinct"
The user can then select from the list one or several items they are intersted in and i want to use these as the filter in a further database call. It's not then difficult to have a where to filter on one string however, I would also like to be able to allow the user to select several items from the list box and the data for all of those to be returned.
[Code]...
View 2 Replies
May 4, 2012
[code]How do I update the ProdServiceID in the database using LINQ to entities?
View 1 Replies
Aug 4, 2011
in my tableadapter query i have a count function "COUNT(PRIMVENDOR)" to give me the number of rows in each group by:
SELECT VENALPHA, PRIMVENDOR, [GROUP], COUNT(PRIMVENDOR) AS GrpCount
FROM ViewCurrentMasterFile
WHERE (PRIMVENDOR = @VenNum)
[Code].....
View 3 Replies
May 29, 2009
The only way I know of is awkward:
'check for empty return
Dim count As Integer = (From s In myEntity.employee Where employeeID = myEmployeeIDVariable).Count
'If there is a record, then process
[code]....
View 2 Replies
Mar 6, 2011
I am trying to write a LINQ equivalent of
SELECT C1, C2, C3
FROM T1
WHERE T1.C4='xyz' AND
EXISTS (SELECT 1 FROM T2
WHERE T1.C17 = T2.C24)
ORDER BY C3
I'm using EF CTP 5, so I have a DBContext variable named dbc, which includes DBSet objects T1s and T2s, based on POCOs T1 and T2.
In LINQ I write
DIM IND = From i In dbc.T1s
Where i.C4 = "xyz"
And (From t In dbc.T2s Where i.C17 = t.C24).Any
Select i.C1, i.C2, i.C3
Order By C3
Running the query I get the error message "Unable to create a constant value of type 'T2'. Only primitive types ('such as Int32, String, and Guid') are supported in this context." When I omit the inner expression (third line in the LINQ code), the query runs fine. I tried switching the orders of the inner comparison, to be t.C24 = i.C17, with no effect.
View 1 Replies
Mar 21, 2012
I had a code segment on an asp.net page in the code-behind file. I decided to move it into a public subroutine in a module (general_functions.vb). Once I did this, however, the code no longer works - it throws an error. On the original code-behind I replaced the original code with a call like so:
[Code]...
View 1 Replies
Nov 16, 2011
I have a simple query as below:
Dim sizings = From a In db.Sizings
Where a.Customer.ID = customer.ID
Select a
If sizings.Any Then
.....
The sizings.Any line is throwing a null reference exception. I thought I was meant to use .Any to determine if there were any rows returned?isnothing(sizings) returns false.
Edit - Resolution:Don't use null objects in the LINQ Query!
View 2 Replies
Apr 24, 2012
The documentation has an example about grouping on multiple properties[code]...
Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?
View 1 Replies
Jun 23, 2011
Here's what I tried, but I get an error at run time on the AddRange line that states "Only parameterless constructors and initializers are supported in LINQ to Entities."
[Code]...
View 5 Replies