locked
how do i access lightswitch database in c# RRS feed

  • Question

  • how do i access the data in lightswitch database? If I want to edit the date or something in my .cs file.

    "select * from database where id =5"  somethign like this?

    Sunday, February 10, 2013 9:58 PM

Answers

  • You can not directly talk to the database in your code without writing a selection of code to do so. Remebering that it is just .net code you will have to ..

    1. Create the connection string

    2. create the conection to the database

    3. define the query object

    4. pass this to an execution method

    5. proces the results.

    But if you are going to be reading the data from tables already defined as entities you can always just reference the collections and then use a linq query against them. This was Lightswitch will handle the relationships, connections and security for you.

    Monday, February 11, 2013 12:16 AM

All replies

  • You can not directly talk to the database in your code without writing a selection of code to do so. Remebering that it is just .net code you will have to ..

    1. Create the connection string

    2. create the conection to the database

    3. define the query object

    4. pass this to an execution method

    5. proces the results.

    But if you are going to be reading the data from tables already defined as entities you can always just reference the collections and then use a linq query against them. This was Lightswitch will handle the relationships, connections and security for you.

    Monday, February 11, 2013 12:16 AM
  • Do you mean an entry were you stored the "a date" previously or actually cracking open the database. If you meant the first then just create a Editable grid screen and edit the entry. If you mean the second go to Glenn's response.

    You can also open the application code which looks like XML but falls under the C# file for each project type. I do this a lot for entry of big items like a huge list of entry options. I that case you have two options I have found both necessary at times. If you simply switch to file view you can click on an application ‘.Isml’ file and the code will appear. If there is something in your code preventing this from the designer you can exit the program and browse to the project C# file in your projects folder and open say the client C# file in Visual Studio and then browse to the application file without the LS Designer running. Be Careful editing these files of course you can mess up the structure in these .Isml files.

    Monday, February 11, 2013 5:10 AM