0

I'm trying to get data from my local database that is present in my app project.

This is the code:

private void HW_Info()
    {
        const string strConnectionString = @"appdata:/WInfoAppDevicesDB.sdf";
        using (DeviceDataContext db = new DeviceDataContext(strConnectionString))
        {
            var projectName = from m in db.Devices
                                 where m.ProductName == deviceName
                                 select m;
        }
    }

The problem is that I didn't obtain values of my table, but a string of SQL query, and I don't know which table app will choose (there are three tables with same columns type).

(I'm newbie with Linq-to-SQL because I studied only SQL, so I apologize for my lack of preparation about it)

4

1 回答 1

1

In the code snippet that you have provided in the question, you are querying the "Devices" table.

Based on your comments, it seems like 'Devices' table is not available in the database that you are using.

In case you want to select records from "HTC" table, change the linq query as below

var projectName = from m in db.HTC
                  where m.ProductName == 'deviceName'
                  select m;

The equivalent SQL query for the above linq query is as below

SELECT * FROM HTC m WHERE m.ProductName = 'deviceName';

Hope this helps...

于 2013-05-31T14:18:23.150 回答