I seem to be missing a step in setting up my database in Visual Studio. I created a .mdf database titled “PhotoDatabase”. In the server explorer I added a new table called “tbl_Photo” which has the following columns: Image_ID, Image, Thumbnail, Name, Description.
Right now I am in my PhotoRepository(.cs) class and am trying to add the image data to my table but it just can’t seem to find the table.
DataContext db = new DataContext(@"C:\Dev\MyFlickr\MyFlickr.WCF\App_Data\PhotoDatabase.mdf");
db.
Everywhere I looked said I should be able to see my table name after the db. Help Please!
I think I have found your problem. It looks like you have not created a dbml file to map your tables to entities. What you need to do is add a new item to your project. Under the “Data” subsection, you will see “LINQ to SQL Classes”. Add that and then drag your table onto that class from your Server Explorer window. After that, you should be able to see your table as an entity and the above code should work (or code close to it). For instance, I created a file like you have and the following code works:
In order for it to work, though, I had to create that dbml file and add Table1 to the designer. For more information on how to use this code, you can look at this MSDN article: http://msdn.microsoft.com/en-us/library/bb399375.aspx