Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving info from database

Tags:

c#

linq-to-sql

I'm going to retrieve information from a database using LINQ but I don't know why I'm getting this error:

Invalid object name 'Retriveinfos'.

My class is here:

[Table (Name="Retriveinfos")]
public class Retriveinfo
{
        [Column]
        public string Name { get; set; }
        [Column]
        public string LastName { get; set; }
        [Column(IsPrimaryKey = true)]
        public int Id { get; set; }
    }

and then using this line of code to connect and retrieving information:

DataContext dcon = new DataContext(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Second_School_project\Review_Site\Review_Site\App_Data\ReviewDatabase.mdf;Integrated Security=True;User Instance=True");
Table<Retriveinfo> Retriveinfos = dcon.GetTable<Retriveinfo>();

var c = from d in Retriveinfos
        where d.Id == 1
        select new { d.Name, d.LastName };

foreach (var a in c)
    Response.Write(a.Name.ToString() + " " + a.LastName.ToString());
like image 593
Hussein Ojaghi Avatar asked Jan 18 '12 09:01

Hussein Ojaghi


1 Answers

Well Retriveinfos is a table in your database not a class you may need to use something like the entity framework to create classes to represent you tables before you can do something like the above

like image 69
Andy Stannard Avatar answered Oct 27 '22 00:10

Andy Stannard