Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ
private Table1 Result() 
{
   Table1 t = new Table1();
    var q =
        from k in DataBase.Table1s
       where k.Id>0
        select k;
t = q;//Erorr!! How To Resolve This Section.With Cast Also is Not Resolve

return t;
 }
 
I have one table.it Name is Table1
I want to Return Result this Query with Table1 Objects?
but I Dont Know!!!
Posted 5-Aug-12 18:49pm
Edited 5-Aug-12 21:14pm
v3
Comments
Santhosh Kumar J at 6-Aug-12 3:24am
   
have u tried solution 1?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

private Table1 Result()
{
Table1 t = new Table1();
t =
DataBase.Table1s.Single(k=>k.Id>0);
 
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Try this:
private Table1 Result()
{
    // Suppose your DataContext class name is TestDataContex. 
    TestDataContext ctx = new TestDataContext();
    var Query =  from c in ctx.Table1s select c;
    // Now you got a query. Use it as required.
}
 
Refer Understanding LINQ (C#)[^] and Using LINQ to Objects in C#[^].
 

All the best.
--Amit
  Permalink  
v2
Comments
Seyed Ahmad Mirzaee at 7-Aug-12 2:23am
   
With This Code Error Again Occured!!!
"Error:Can Not Convert System.data.linq.IQueryable<Table1> to 'Table1'.an Explpicit Conversion exist.are you missing cast?"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 489
1 ChintanShukla 295
2 Gihan Liyanage 250
3 Richard Deeming 250
4 RyanDev 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,601
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,923


Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 6 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100