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
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].....
How can I databind from my xml file to my treeview?I didn't like my way of populating a tree view, coz of it doesn't go with my UI when I was creating an xml file then load it to the treeview...
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.
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?
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
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?
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.
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.
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.
'check for empty return Dim count As Integer = (From s In myEntity.employee Where employeeID = myEmployeeIDVariable).Count 'If there is a record, then process
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.
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:
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!
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?
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."
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 be Table2WhereColumn1 and Table2WhereColumn2, and the query (which works) looks like this:
I've tried using Group Join with DefaultIfEmpty(), as well as an implicit join (without the actual Join keyword), and I only get rows for items that have values in Table2. I'm sure this won't help, but here's an example of the Linq I've been trying that doesn't work:
Public Shared Function GetProfilePreferencesForCedent(ByVal dc As EntityContext, _ ByVal where1 As Int32, _ ByVal where2 As Int32) _
I have a GridView and on a row being deleted I trigger the GridView1_RowDeleting sub, but I receive an error "LINQ to Entities does not recognize the method 'System.Web.UI.WebControls.TableCell get_Item(Int32)' method, and this method cannot be translated into a store expression." Code is:
Private Sub GridView1_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting ' The deletion of the individual row is automatically handled by the GridView. Dim dbDelete As New pbu_housingEntities ' Remove individual from the bed.
When I execute the code below I receive the error message: LINQ to Entities does not recognize the method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' method, and this method cannot be translated into a store expression.It seems to be occurring on the line For Each row2 in PCstudent.
I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows:
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.
I have the following LINQ-to-Entities query:[code]This will give me all the resident assignments for the current year/term. Then I have this LINQ-to-Entities query:[code]This will give me all the rooms. I want to iterate through the assignments and based on what room is assigned update the occupancy in reset_occupancy. I'm not 100% sure how to accomplish this. Here is my pseudo code of what I want to accomplish:[code]
Using advWorksContext As New AdventureWorksEntities ' Call the constructor that takes a command string and ObjectContext. Dim productQuery1 As New ObjectQuery(Of Product)("Product", advWorksContext)
[code]....
An ObjectQuery can be enumberated only once. (Subsequent attempts at enumeration throw an exception.) The enumberation takes place in the for each statement. The problem is that if the query is empty attempting a For Each will throw an exception. But if I check for a count:If productQuery1.Count > 0 Then . . .
That eats up my one chance at enumeration. I could nest the For Each in a try/catch block and throw away the empty query exceptions, but that's ugly.
Public Class CalculationParameter{ public Long TariffId{get;set;} }
In a workflow activity, I've an Assign like this:
(From tariffDetail In db.Context.TariffDetails Where tariffDetial.TariffId = calculationParameter.TariffId).FirstOrDefault()
Dto is passed to Activity as an Input Argument.It raise following error and I'm wondering how to assign Id.LINQ to Entities does not recognize the method 'Int64
GetValue[Int64](System.Activities.LocationReference)' method, and this method cannot be translated into a store expression.
How can I assign the calculationParameter.TariffId to tariffDetial.TariffId?!
UPDATE:Screen shot attached shows that how I'm trying to assign calculationParameter.TariffId to tariffDetail.TariffId (car.Id = Dto.Id) and the query result should assign to CurrentTrafficDetail object.
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 want to create a treeview from a database in my project. I have been using linq to retrieve data. I have TeamLeaders, Marketers and Clients. When i expand the TeamLeaders node i want to see the Marketers under that node and when I click on the Marketer. I want the list of clients under that Marketer to be displayed on the right panel that has a gridview. TeanLeaders and Marketers are from one table and Clients in a different table.