.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Missing a cast in Linq Expression

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
 Hi, My code is: var results = from XPathNavigator res in iterator  where res.Select(xpath).Current.Value.Contains(param) select res; where iterator is XPathNodeIterator. I get the next error(on where ): Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Xml.XPath.XPathNavigator>' to 'System.Linq.IOrderedEnumerable<System.Xml.XPath.XPathNavigator>'. An explicit conversion exists (are you missing a cast?) Where am I  missing a cast? Thanks, katzraya        

View Complete Post

More Related Resource Links

Cast error when inserting record with Linq (to Sql)



I'm getting  the following error message: 

Unable to cast object of type 'System.Data.Linq.DataQuery`1[Username]' to type 'Username'.

I've been searching but can't find a solution.  This particular table has 4 columns. The first column is the int indentifier.  Column 2 is "username" (varchar50) and is the primary key.  Column3 is "userID" (uniqueidentifier) and column 4 is "active" (varchar5) .

            Dim dc As New DataClassesDataContext
            Dim c3 As New Username With {.userID = userGuid, _
                                    .username = userCustomName, _
                                    .active = "False"}


        Catch ex As Exception
            Throw ex
        End Try


Syntax error (missing operator) in query expression

Good Day Gurus!

I have a Excel user application which has a user form (named 'Registo') that displays criteria and an image that has been entered in it's corresponding spreadsheet. This works the way it should.  There's also the ability to search the spreadsheet via a form (by clicking 'Pesquisar' button) this opens a search form. However, I having a bit of a problem with it. When I try to search for something it basically doesn't do anything at all. It just sits there. So I tried to debug it and I think I'm having a problem with either the JET db engine or somethign with teh query or maybe I don't have the correct reference.

I 'borrowed' this Excel application from another forum because it's exactly what I'm looking for! However, I suck at vb.

So I was hoping somebody could take a look at the code and see if I'm missing something?  I'm kinda' desparate to get this working because I'm been trying to figure it out for days and I'm running out of time.  Cry
Option Explicit

'constantes para auxiliar na verificação do código
Private Const Ascendente As Byte = 0

AllItems.apsx sort by expression missing

Hello, I am using SPD and would like to add a sort expression to my default view to sort a list - why is this feature not available and is there any way to do this? Thanks... 

Field method missing with LINQ query

H, I want to access the data from datatable object. When i trying to get the fieldslist usng "Field" method. But I could not find the method with my table object.  Eventhoguh i forcibly write a method and trying to access the fields, It is giving the below error for the first join in query. Rest of the lines are fine. What is the reason behind it. The errro: "Error 2 'LINQ2DB.SP_VS_OP' does not contain a definition for 'Field' and the best extension method overload 'System.Data.DataRowExtensions.Field<T>(System.Data.DataRow, string)' has some invalid arguments" What is the meaningof the error. Shall i do any other changes in the query line?                         var QueryChnl = from oSPOP in SPOP.AsEnumerable()                        join oDiscChannel in DiscChannel.AsEnumerable() on oSPOP.Field<int>("spid") equals oDiscChannel.Field<int>("SPID")                        join oChannel in Channel.AsEnumerable() on oDiscChannel.Field<in

SSIS 2008-Variable Expression Type Cast Syntax Error


Hi all members.

I need to ask for the following code. I need to convert the variable into a string.

"Select Distinct convert (int ,A.CustomerCategory) as AccountReceivableCategoryID, convert (varchar(40), B.Text) as AccountReceivableCategoryNameE
from Inkunde A , inpara B
where A.CustomerCategory= B.SearchItem
and B.Language1 = 'EN'
and B.ParameterName = 'CATEGORY'
and A.CustomerCategory = (DT_STR,200,1252) "+  @[User::CategoryID] +"
Order By A.CustomerCategory"

Kindly any member let me know, How to correctly use the Type Cast fucntion in variables

Thanks and Best Regards,


missing "linq" assembly? tried several fixes and no luck


Newbie at this so pardon me from the onset...

I'm building a site using VWD 2010 Express.  The site seems to run fine in the browser but when debugging I get the following errors:

Error 1 c:\....\Site.master.cs(3): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)  (I get this message 4 times)

Error 5 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) 

I've gone in to the Web.config and added the following:


<add assembly

Linq to SQL Template missing


I have VS2008 SP1.. I have a web site that I want to add some Linq to SQL functionality, where is the template located? I can not find it anywhere in the web site or projects templates. What do I need to do to get this template for VS2008?


Specified cast is not valid during using LINQ


I am having problem, Please help me guys .....

these are the errors:

Server Error in '/FYPasp' Application.
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
   System.Data.SqlClient.SqlBuffer.get_Int32() +5002837
   System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i) +38
   Read_DynamicClass1(ObjectMaterializer`1 ) +322
   System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +32
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58

These are the codes:

string metric = Session["ID"].ToString();
            string status = null;
            var onlineStud = db.students.Single(s => s.metricNo.Equals(metric));


Custom database function cannot be translated into a LINQ to Entities store expression



I'm trying to get a UDF from my SQL Server database to map to Linq to Entities. I've found an example for the CourseManager sample in the MSDN :




Sub Button1_Click(

Linq to SharePoint(SPMetal) Missing "Author" and "Editor"


So I have also noticed that using the SPMetal tool the CreatedBy(Author) and ModifiedBy(Editor) fields are missing from Entity Model generated by the SPMetal utility. So here is a nice post on manually adding them (http://blogs.microsoft.co.il/blogs/itaysk/archive/2010/02/19/spmetal-missing-created-by-modified-by-fields.aspx), but does anyone know if this is going to be fixed in the future or if there is a reason why they are not generated?


Error: cannot be translated into a LINQ to Entities store expression


When I run my code i get this error:

The specified method '{0}' on the type '{1}' cannot be translated into a LINQ to Entities store expression

it happens in this part of the code:

 public Boolean valtOpVerlofDag(Dictionary<string, object> afw)
            DateTime start = DateTime.Parse((string)afw["startDatum"]);
            IEnumerable<Period> holidays = from hol in periods
                                               where (hol.Type == "Holiday") && hol.IsInPeriod(start)
                                               select hol;
            if (holidays.Count() == 0)

Design view missing in expression blend 4

When i open my project (its not a silverlight project btw just a standard)  i can only see my code and the xaml but no actual design view, but if i open the project in Visual Studio i can see my forms, this is really annoying as im in the middle of a project and also if i open other projects in EB i can see them fine so just his project, any help please?

Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend