ADO.NET :: LINQ And Cast Row To IEnumerable?
Apr 1, 2011table1 row = _db.table1.FirstOrDefault(r => r.ReferenceID == refNumber);
Is there anyway to cast row to IEnumerable?
((IEnumerable<table1>)row) - does not work
table1 row = _db.table1.FirstOrDefault(r => r.ReferenceID == refNumber);
Is there anyway to cast row to IEnumerable?
((IEnumerable<table1>)row) - does not work
I have following code in my class file which returns me the Date field in format like 4/4/2010 12:00:00 AM from SQL SERVER
public IEnumerable Mthgetcomplaintdate()
{
var v = objderma.USP_Patient_Dermatology_Complaints_RepDate(PatientID); ;
return v as IEnumerable;
}
But on my aspx page i want to display only the Date part not time.One way is i will iterated throgh my dropdownlist which am binding with the above method and i convert it using Toshortdatestring() method.But i want to cast the whole Ienumerable result using some method? I have read about cast<> ,but could not understand how to implement it exactly.
How can i convert following sql guery to LINQ in C# ? I dont need all columns from both tables and the result set should be IEnumerable<DataRow>
select c.level,cl.name,c.quantity
from dbo.vw_categories c
left join dbo.vw_categoriesLocalization cl on c.level = cl.level and cl.language = 'en'
where c.level like '000%' and c.level <> '000';
I am having a lot of the same issue as this poster did with errors on initializing type.
I am trying to learn linq and am about ready to give up - don't get how this is easier...
I'm trying to do a simple update to product names in the product table based on the manufacturer ID
In order to do this I am looping through each record. I was initally successful with changing all names in the column but when I try to query the data, I continually run into multiple problems.
The following poster has had the same issue I have but his solution isn't working for me.
[URL]
I keep getting the same error on the opening bracket on the select statement in the SelectByManufacturerID function...
Error 1 Cannot initialize type 'DataBaseDataManagement.ProductName' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
Button that does the actual updating...
[Code]....
The function that the button calls to get the query... ERROR
[Code]....
The class located in Query.cs...
[Code]....
IEnumerable<DataRow> query = (from obj1 in objeDC.tmpPolicyRenewals.AsEnumerable()
where obj1.AgentCode == "Admin"
select new
{
obj1.Product,
obj1.PolicyNo,
obj1.Insured,
obj1.EffDate,
obj1.ExpDate,
obj1.GrossPrem,
obj1.Status
}) as IEnumerable<DataRow>;
Getting null value. whats error ?
I am having problem, these are the errors:
[Code]....
These are the codes:
[Code]....
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:
[Code]....
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.
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)
[Code]....
I have a complicated join between a few tables but I have managed to replicate the error using linqpad and the small tables below. There are references between the COLNAME column and the YAXIS column and also between COLNAME and XAXIS that is not explicitly defined.
The error is "Specified cast is not valid", which originally I wasted time thinking the problem was converting the data returned to my object in VS 2010, but the error also happens in linqpad with no defined object. It seems insane that a bit column would cause this problem. If I change the column type to a VARCHAR it works fine. If I run the generated SQL from linqpad or sql profiler that also returns fine.
[Code]....
I have a database table called Animals which I drag on to my Linq to SQL DBML file.
This creates me a class called Animal.
I then create a class to extend it, like so:
public partial class Animal{
//my extra code here
}
But what I also want to do is have a class like this:
public class Zebra : Animal{
//even more extra code here
}
The trouble is I get an InvalidCastException from my repository, when I do this:
Animal a = dataContext.Animals.Where(c=>c.id.Equals(id)).SingleOrDefault();
return (Zebra)a;
I've stripped back my classes to the point where they're completely empty in an attempt to work why it doesn't work. To no avail.
This casting process did used to work in the non-LINQ-2-SQL project that I'm switching to MVC/LINQ.
I wanted to delete the record from data but I receive this error "Unable to cast object of type 'System.Data.Linq.DataQuery`1[training_eval.Course]' to type 'training_eval.Course'.
Dim eval_sure = From ev In db.Evaluates Where ev.course_id = indexcourse Select ev.course_id
Dim del_course = From c In db.Courses Where c.Course_id = indexcourse
db.Courses.DeleteOnSubmit(del_course)
db.SubmitChanges()
App Details:
C#, ASP.NET MVC, SQL Server 2008 ( Same version & SP level), Linq-To-SQL ORM
I'm trying to diagnose an exception I'm receiving:
"Specified cast is not valid."
at System.Data.Linq.IdentityManager.StandardIdentityManager.SingleKeyManager2.TryCreateKeyFromValues(Object[] values, V& v)
at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache2.Find(Object[] keyValues)
at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
at Repository.Save()
at etc....
The problem is that this is occurring only on our servers, not on our local development boxes. I've tracked it down to a single property we're modifying:
event.SalesForceId = "701Q0000000AOTIIA4";
If I comment out that line, everything works fine.
I've tried:
1 ) waxing all of the code on the server and redeploying. Same issue.
2 ) Pulling down a copy of the server DB and trying it locally. Works fine.
3 ) Trying another IIS environment we have setup on the same box. Same issue.
4 ) Physically comparing ( using AdeptSQL ) both local and remote schemas. No differences.
5 ) Verifying the datatypes of both columns ( local and remote ) are the same. Also, this column is a FK to another table. I verified that both are of the same data type, down to the collation.
The server is Windows Server 2008 and the local box is Windows 7 x64. Both have all important updates setup.
The only thing I can think of is perhaps since the database and web server are on different boxes that could be an issue? Otherwise, I'm completely stumped.
I have an Interface that has its concrete class defined via a factory. Because of this I found no way to use the Interface tpye directly in my LINQ quesry so I had to use the concrete class types to creat a generic list. The LINQ query works but after calling.ToList() on the LINQ query result I get a List(of MyConcreteClass), but I need a List(of IMyConcreteClass). I have tried everything I can find: .Cast, Ctype, implicit casting, etc. but I always get back one of the (2) messages (depending on if I attempt to cast)message:
"Unable to cast object of type 'System.Collections.Generic.List`1[MyConcreteClass]' to type 'System.Collections.Generic.IEnumerable`1[IMyConcreteClass]'."
...or
"Unable to cast object of type '<CastIterator>d__aa`1[IMyConcreteClass]' to type 'System.Collections.Generic.List`1[MyConcreteClass]'."
Here is the sample code:
[Code]....
i was looking at one example on msdn [URL], but i can't really understand it.
View 1 Repliesrefer me few article which describe the basic use of IEnumerator and IEnumerable,
View 3 RepliesI have function it will return IEnumerable as.
IEM = myclass.getdata("name");
How to read the data in IEM as it consists of many columns. I have to display the values into labels and textboxes.
I am using LINQ for data connectivity and have made class which return me the result set into presentation here is the syntax:-
public List<ClsDermaInvestigation> MthdisplayInvestigation()
{
List<ClsDermaInvestigation> lstinvst = new List<ClsDermaInvestigation>();
ISingleResult<USP_Patient_Dermatology_InvestigationResult> investresult = objderma.USP_Patient_Dermatology_Investigation(PatientID, RepDate, Hb, TLC, F);
foreach(USP_Patient_Dermatology_InvestigationResult rel in investresult)
{
ClsDermaInvestigation objinvest = new ClsDermaInvestigation();
objinvest.Albumin = Convert.ToDouble(rel.Albumin);
objinvest.ALP = rel.ALP;
objinvest.ANA = rel.ANA;
objinvest.Date = rel.date;
lstinvest.add(objinvest)}return lstinvest}
This list is returning me the result.It works fine but in 1 case am using the same list to bind my Date dropdownlist.
//aspx.cs code
List<Dermatology.ClsDermaInvestigation> objlstinvest = objinvest.MthdisplayInvestigation();
//Array s = objlstinvest.to
drpDate.DataSource = s;
drpDate.DataTextField = "Repdate";
drpDate.DataValueField = "Repdate";
drpDate.DataBind();
But it throws an error that list does not conatin a property with "Repdate";. How can i bind this list with dropdownlist?? Can i convert it into some type so that i would be able to bind it??
I'm trying to update values I have stored in an IEnumerable using UpdateModel, but it isn't reflecting the changes when I step over it in Debug.I also tried upating it using a foreach loop and updating the values in each object T within the IEnumerable<T>. The values are changed at the object level, but it seems that the value of the object in the IEnumerable isn't being changed.I was looking at IEnumerable<T> and didn't see a way to update it... I'm thinking that I might have to assign the updates to some other data structure, then convert it to an IEnumerable or something before I try to save my repository
View 6 RepliesI've read some articles about this but for some reason they're just not doing it for me. I'd like to understand the difference between
IEnumerable<string> myList and List<string>myListToo
I have IEnumerable object with value1 and value2. value2 is an array and value1 is string. I want to databind this object to Listview like that. So both value1 and value2[0] (always first item in array) could be accessed via <%# Eval("value1") %> and <%# Eval("value2") %> .
How to write expression to handle both items ?
ListViewItems.DataSource = f.Items.Select(t => t.value1, t.value2[0]);
ListViewItems.DataBind();
I have an IEnumerable< T> which is declared on the page like this:IEnumerable< Person> person;When the page postsback, the person list is null. How can I retain the values of person list without declaring it as static? Sr. devs in my company say that you should not declare the list as static.
View 2 RepliesDim list As List(Of DataRow) = dt.AsEnumerable().ToList()When I compile I get the error:
'AsEnumerable' is not a member of 'System.Data.DataTable'.I added Imports system.data.datatableextensions to the file..This code works when I run it on a asp.net project But when I use the same code in Website it returns the above error..Can anyone help solve this error.
i'm using MVC 2, RC, and i have a controller method:
[Code]....
and i have an <input type="file"../> in my form. during post, however, the files parameter is null.
My controller has a member that returns a JsonResult object, it is coded as per below. The problem is that Json(users) only returns the data from IEnumerable (MembershipUserEx objects) and I also want the data from the public Properties of MembershipUserExCollection as well. Is there a way to do this? I guess I am looking for the Json object to look something like this pseudo object:
results = {
pageIndex:0,
pageSize:50,
[code]...
Why it's not possible to cast a SiteMapNodeCollection (eg. SiteMap.CurrentNode.ChildNodes) to an IEnumerable<SiteMapNode>? I was wanting to do some filtering of the collection via LINQ, but this might not be possible?
The MSDN page says it implements IList, ICollection, and IEnumerable, so I don't see what the problem is.