I have a list(of object) lets say ob1,ob2,ob3 that are classes I want to write a linq-querry that exstract from this list only one particolur object that is different time to time how can I write the linq querry?
dim List as new list(of Object)
list.add(ob1)
list.add(ob2)
list.add(ob3)
dim Result=(from P as ob3.gettype in list select p).tolist
I wanted to define a property which accepts decimal numbers and do some process on the value and return string such as the below:
Public Property Amount() As String Get Return Utility.PaddingRight(Me.msAmount.ToString(), 10) End Get
[code]....
But compilers warns "Set parameters must have the same type of the containing property."It doesn't look like it should throws an error since it looks legit.
I'm using the Hashtable class for the first time, and have a question about it:Is it possible to define a type for all it's elements? So that when you for example only put strings in it, you can retrieve them without having to cast them from objects.
Im trying to grasp session varibles, i understand what they are etc but i would like to know how to define a type for each session variable.Iv written it like this
Session("Title") = txtTitleContent.Text
How can i tell it what type of value is going to be in it, because at the moment im only playing about with strings, but what if i have an integer and want to pass it back to the back end to save it will throw an error saying "conversion from string to integer is not valid" should i use Cint to deal with this?
I'd like to create a user-defined data type in VB.NET but don't know how to do it.Take an example.......say there's a variable to control the action of a timer control. The possible actions would be "no action", "run timer", and "stop timer."I could do this with an integer (e.g. 0=no action, 1=run timer, 2=stop timer), but I'd rather create a data type so that the options are more explanatory than a simple integer. Like so....
Private Timer_Action as MyDataType Timer_Action=MyDataType.RunTimer
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 am trying to redirect command line output to a list box in a vba macro, and I've found some code that I think might point me in the right direction, but I keep on getting the same error. When I use this code [code]It gives me the error in the title and highlights the first declaration line.What does it take to define a new "process".
I am getting a really bizarre error and it makes no sense at all.Basically I have a user entity which has a Password property. This property is of Type Binary, the server data type being Binary(512).I am reading this value in and converting it to a byte array. However whenever I run my code I am getting a completely unrelated error of Unable to cast object of type 'System.Guid' to type 'System.String'.This strikes me as very odd since I am not using a property or variable of type string or GUID anywhere in this procedure where it falls over.
The code is below:
Public Shared Function ValidateUser(ByVal username As String, ByVal password As String) As UserValidationMessage Using db As New EntityMapDataContext Dim u = From user In db.Users Where user.Username = username
I'm out of my depth populating a windows form from an XML linq query (see code further down in post). The listbox is populated as intended, when a value is selected (row) I would like to populate the remaining form controls. The linq query I believe has created a new datatype "Anonymous Types". The query is only local to the load form subroutine but I'm not sure how to make it global.
When I define the query simply as an object the code in the selectedValueChanged event can't execute due to late databinding. how I can initially load the listbox from linq xml query and then populate the other controls when the value changes? Am I right in thinking even though the listbox is multi-columns (property) you can ONLY ever reference a row and NOT a column? I'm new to LINQ and Anonymous Types and the more I read the more confused I seem to get. On a less important note the order by is not functioning as intended (no errors) but data is always retrieved in xml file order and not by the node <text>. Also looked at using <text>.first to order the results without success.
Dim mYVariable = From C In dtXMLConverter Select C I am using the above mentioned syntax for getting the rows in the variable named "mYVariable" after issuing the from clause when I am moving my mouse cursor on the variable name, it is showing "Dim mYVariable As Object" instead of showing DataRow or something like that. I can't understand how to solve this problem.
I am querying a datagridview and it works great unless one of the cells has nothing (dbnull). How to over come this?Exceptions: Operator '=' is not defined for type 'DBNull' and type 'DBNull'.
Dim query = From row As DataGridViewRow In DataGridView1.Rows _ Where row.Cells(SelectedColumnIndex).Value = filter _ And row.Visible = False _ Select row Distinct
Dim rsPublicChilds As System.Data.Linq.ISingleResult(Of spGetPublicObjectsResult) = Nothing rsPublicChilds = dc.spGetPublicObject(slintLoginID, lintLanguageID, lintObjectID, lintObjectTypeID, lstrSEOURL, lstrValid)
I get an enumerable list of rsPublicChildObjects that I then convert to an array;
Dim larr_PublicChild As IEnumerable(Of spGetPublicObjectsResult) = rsPublicChilds.toArray()
That then gives me easy access to an array of the objects, so I can then do;
larr_publicchild(0).colMyValue
etc.etc
I'd like to get the minimum value of colMyValue (or any other property of the object that's been created for me) but I can't quite see how to get there.
I am using linq to fill a gridview with the information from an xml from code behind. I would like to order my Grid according to one of my elements in the xml ("value element").
gvResourceEditor.DataSource = (From resElem In resourceElements.Elements("data") _ Select New With { _ .Key = resElem.Attribute("name").Value, _ .Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _ .Comment = If(resElem.Element("comment") IsNot Nothing, HttpUtility.HtmlEncode(resElem.Element("comment").Value), String.Empty) _ }).OrderBy(?????)
Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??) Using db As New MyEntity Dim query= (From A In db.Account _
[Code].....
I would then like to pass this to another function to calculate the totals for all the accounts in the collection. Is it best practice to return an Ienumerable, a generic list, I'm just not sure what works best with LINQ and the entity framework.
An old Yet Another Language Geek blog post explaining monads describes adding a SelectMany extension method to C# in order to extend the linq syntax to new types.I've tried it in C# and it works. I did a straight conversion to VB.net and it doesn't work. Does anyone know if VB.net supports this feature or how to use it?
Here is the C# code which works:
class Identity<T> { public readonly T Value; public Identity(T value) { this.Value = value; } }
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 am using VB .Net for this, so I don't have access to var or this would be a simple matter.Right now my query is as follows
[code]...
So I used this query in LinqPad to help me determine what the object would look like. I got back a IOrderQueryable(Of RSError) which then contained a IGrouping(Of String, RSError) for each grouped collection of objects returned by the query.However I ended up with the current object type of errors as IOrderedQueryable(Of IGrouping(Of String, RSError)) because of the cast error I am getting in VS.
[code]...
I'm not sure how to get rid of the VB$AnonymousType_1 Part of the returned object.Am I even on the right track here or am I missing something completely?
OK I have a base query that is returning a list (ObjectQuery, actually but I don't think it matters) I have about 5 subtypes based on the main type and I need to filter them. Everything works fine until I want the results to be of the main type (not a subclass) Basically I have a query that includes everything, then I filter out the types that are not checked in a checkedbox list. (asp.net) Lets say I have an Entity named Task, and SubTask1 and SubTask2 that inherit from Task
I have a database with a simple flyweight table referenced by another table. Let's call them, respectively, Category and Product.The Product table has several columns, one of which is a foreign key column (complete with constraint) to the CategoryID to a row of the Category table. It's simple, and I have many of them in this particular database.
I am using Linq in Visual Studio 2008 to represent this data in my application. Both tables appear as normal, and neither have anything special in their properties that would indicate the behaviour I'll describe.In the database itself, there are several Product rows which have CategoryID=1. There are two or three that have CategoryID=2. However, when the data is loaded into my application through Linq, iterating through context.Products shows that the first three have CategoryID=1, CategoryID=2 and CategoryID=3, and all the rest of the rows have CategoryID=NULL. This is not how it appears in the database. There are no other anomalies in this database.
I have the following Data Transfer Objects defined:
Public Class MemberWithAddressesDTO Public Property Member_PK As Integer Public Property Firstname As String Public Property DefaultAddress As AddressDTO Public Property Addresses As IQueryable(Of AddressDTO) End Class
I'd normally do this in C# but since I've got to get this code in this particular assembly which is a vb.net one, I'm stuck.
Here's my linq query:
Dim i As Integer = 0
Dim oldAndCurrentIntersectionOnNames = From currentApplicant In currentApplicants _ Group Join oldApplicant In oldApplicants _
[CODE]...
You'll see the .Index = i+=1
This was my attempt to do what I'd quite happily do in C# (i.e. Index = i++) in VB. Unfortunately the VB compiler doesn't like that. how I'd do this in VB.
Ok, just needing a 2nd set of eyes looking at this to make sure the error isn't something else other than my LINQ code here. Here's the function class itself:
Public Function GetJacketByPolicyID(ByVal jacketID As Int32) As tblPolicy Dim db As New DEVDataContext() Dim j As tblPolicy = db.tblPolicies.Single(Function(p) p.policyNumber = jacketID) Return j End Function
and here is the code which calls this class function in the web control form itself:
Dim p As tblPolicy Dim j As New Jackets() p = j.GetJacketByPolicyID(3000050)
For some reason it's flagging the 2nd line in the GetJacketByPolicyID function saying the specified cast is not valid. So I'm guessing it's something I'm doing wrong. I'm sure the tblPolicy/tblPolicies class works right since I can create a new instance of a tblPolicy and set a few variables by hand and return it, so that's not it. I've also checked the datarow I'm fetching and there's no null values in the record, so that shouldn't be it either.