Update One Entity Based On Results Of Another LINQ-to-Entities Query
Apr 9, 2011
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]
View 1 Replies
ADVERTISEMENT
Dec 15, 2009
I have the following LINQ-to-Entities query:
' Get all the residency assignments that match the term/year.
Dim assignments = From p In dbContext.Residents _
Where p.semester = term _
[code].....
View 1 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
Apr 24, 2009
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:
grid.DataSource = myEntities.entityName.Where("it.field = " & field)
It works, but it obviously isn't strongly typed. Is there a way to define the Where clause of an entity using a strongly typed notation?
View 1 Replies
Dec 30, 2011
I'm working on modifying this example:
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.
View 2 Replies
Jul 9, 2010
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.
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
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
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
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
May 4, 2012
[code]How do I update the ProdServiceID in the database using LINQ to entities?
View 1 Replies
Mar 14, 2011
I have a simple If..Then like so:
If rhcexists.First.SignatureDate > Date.Today.AddMonths(-6) Then
End If
rhcexists is a simple query to the Entity Model:
[code].....
View 1 Replies
Mar 14, 2011
I have a simple Entity query:
Dim rhcexists = From p In dbContracts.Signatures _
Where p.StudentID = people_code_id _
And p.ContractType = "rhc" _
Order By p.ID Descending _
Select p
I then check whether one of the result values is more recent than six months ago using an if..then like so:
If rhcexists.First.SignatureDate > Date.Today.AddMonths(-6) Then End If
However, if there are no results returned this will return an error. Is there a way for me to tell it to act as if the date is older than six months if there is no value at all? e.g., could I in pseudo do something like:
If Exists(rhcexists.First.SignatureDate, Date.Today.AddMonths(-8)) > Date.Today.AddMonths(-6) Then End If
View 2 Replies
Oct 10, 2010
I have a query that will go away an and find data
Dim HSNs As String = String.Join(",", ListOfHSNs.Cast(Of String)().ToArray())
Dim query As String = "SELECT VALUE O FROM v_BillData AS O WHERE O.HSNumber IN {'" & HSNs & "'}"
Dim hs As New ObjectQuery(Of v_BillData)(query, CType(Session("ObjectCon"), ObjectContext))
What I now wish to do is to use the results of this query to databind to a EntityDataSource?
View 1 Replies
Mar 19, 2012
I have created a database that allows me to sort through the hundreds of pictures I have based on certain criteria. The file path for each picture is stored in a text box in the database (file path). I am currently using this code to copy the files to a new folder:
My.Computer.FileSystem.CopyFile(file_pathtextbox.text, �E:photo_gallary�)
However, this only copies the first file in my query not all the others. I am at a loss as how to loop through them all so they all end up in their new destination.
View 8 Replies
Sep 11, 2009
I have used linq quite abit but was just wondering how to append the results of two IEnumerable(of X) together into one IEnumerable(of X)
View 4 Replies
Aug 18, 2010
In an application for a Storage company, I have a form with 107 buttons in five Group Boxes. Each Group Box represents a Building and each Button represents a Storage Unit. They are layered in Table Layout Panels, bottom TLP has 5 columns, one for each Group Box, each Group Box has a TLP with 2 columns and 10 rows, where each button is located. What I would like to do is change the color of any button based on the results of a query.
Buttons are called btn1, btn2, btn3..... Text on the buttons is 1, 2, 3, 4,.... I have a table for the buildings and one of the properties is "Available" set as an intger and is either 0(No) or 1(Yes). I have a query that I run on form load that returns the correct results, to test I put a DGV on a form and set the DataSource to the DataSet returned. Returned is the "Available" Buldings Number(1-107)[code]...
View 16 Replies
Mar 5, 2011
I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It uses Where conditions to narrow down the results, namely:
Gender.Current Occupancy < Max Occupancy Available Flag is Checked I know this should return results but it keeps returning an empty set.Code is below
[code]...
UPDATE: I've verified that the issue is with the statement where sh.is_available = 1, which doesn't make sense since this is a bit field.
View 3 Replies
Jul 20, 2011
I'm doing some XLINQ in VB for work. I basically need to pull some values from a small chunk of XML as listed here:
<?xml version="1.0" encoding="utf-8"?>
<Fields>
<typeQtyRadioButtonList>1</typeQtyRadioButtonList>
<cmbQtyCheck>Reject</cmbQtyCheck>
[code]....
... Leaving out the implementation of the For Each loop....So I have stuck a break point on the for each and the collection has no elements in it.
View 1 Replies
Mar 3, 2009
I have the following code:
Dim db As New linqclassesDataContext
Dim categories = (From c In db.faq_cats)
NewFaqDropDownCategory.DataSource = categories
[code]....
View 3 Replies
Feb 3, 2011
In my application, I have a search query textbox (txtSearch) that works well with one-word queries with the following LINQ:[code]So how would I make the above query more generic (ie: able to handle any number of words in a query)?I should note that the object being queried is a List of strings pulled from an Access database. As it stands, this application only queries the database once and I'd like to keep it that way if possible.
View 3 Replies
Dec 7, 2010
I have a VB .Net linq query that I want to return values from two tables. I currently have this:
Dim query = (From c In db.Client _
Join u In db.Users _
On u.UserID Equals c.UserID _
Where (c.ClientID = 1)
Select c, u).ToList
query (System.Collections.Generic.List(Of )) returns several rows as expected each item containing a c and a u.
How do I iterate through the queries collection?
View 1 Replies
Sep 25, 2010
i try to convert this kind of sql query into linq in visual basic, but i get stuck on how to make a percent.. I also don't know how to use linqpad for creating this linq
SELECT CASE RIGHT(PICName, 3)
WHEN '(P)' THEN 'Problem'
WHEN '(R)' THEN 'Request'
[Code].....
View 3 Replies
Feb 3, 2011
I have the following routine (that works) but which is messy to update owing to the hand-typed strings it uses:
Private Sub ListDefaults()
Dim conn As New SqlConnection( _
"server=bas047AUTODESKVAULT;Database=DWGDetails;Integrated Security=SSPI")
'Dim conn As New SqlConnection( _
[code]....
View 1 Replies
May 13, 2011
I am using Entity Framework 4.1 code first+MVC3 and the inheritence stratagy that I use is TPC
I have the following classes
Public Class ObjectBase
<Key()>
Public Property Id As Integer
Public Property Description As String
End Class
[Code]...
Question 1 (and question 2) should be very simple, but I have allready spent hours on Google to find an answer with no result at all. The only thing I have found is that you can get all computers in ObjectBase by writing context.ObjectBase.OfType(Of Computer), and that does not help since you cannot write context.BorrowObjects.ObjectBase.OfType(Of Computer) code samples in VB.NET (if you can), but more importantly: Please ensure that the codesamples you supply work without hours of modification!
View 2 Replies
Mar 2, 2011
I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table.
I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum.
Here is the way I implement that. I am looking to prevent using "For each".
iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum
[Code]....
View 1 Replies
Feb 3, 2010
I've got a datacontext and created a binding source using LINQ to sql but cannot filter said bindingsource. The supportsfilter of the bindingsource is set to false ? why ? I can't find any info to say that I cannot filter a binding source based on a linq query.[code]
View 3 Replies
Mar 4, 2009
I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file.OrderDetailsID is a foreign key in Requests Table.I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId.And If there is a row in Requests Table for each rderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum
View 3 Replies
Jul 27, 2011
I am trying to build a survey engine from an existing database design which is like this.
[Code]...
The line Order By Key.RecordOrder throws a null reference exception and I can understand why. Can someone advise on how to resolve this by just modifying this one query? I am fairly new to LINQ and the necessity to write this project
[Code]...
View 1 Replies
Nov 27, 2010
I have two module-level variables and Linq query. I want the results of the Let clause to change the global variables - is this possible?
For example:
Dim X As Integer = 0
Dim Y As Integer = 0
[code].....
View 3 Replies