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());
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With