Pergunta

I've written a separate plug-in application that log users activity in our office using a specific piece of software to a SQL database. The plugin logs when the user opens the application, their computer information, hardware, what files they open, how long it took to open the file etc. etc..

Now I'm trying to use Visual Studio Lightswitch 2012 to make a dashboard to view this data and am having some problems.

First I have a number of computed fields that I want the user to be able to sort by. For example in my database all dates are stored at UTC times, but obviously the user wants to see local times. I found this tutorial which describes creating a separate field that updates automatically with an existing field. Yet this does not work for me because my Table is defined in SQL serer not light-switch so I can not create new write-able fields in the table through light-switch. Nor do I wan to make any changes to my SQL database.

So what I'm wondering now is if there is a way to create separate "ApplicationData" tables in light-switch that are automatically populated/updated from the data in SQL Server when my application starts. And then I would be able to relate these tables to my SQL tables for sorting/searching.

Is this possible and if so where should I put this code? Is there an AppLoad or AppStarting method somewhere that would be the correct place to put this initialization code?

Foi útil?

Solução

The way I would personally do this is:

  1. Attach your SQL database as an external data source (you do this to let LightSwitch create a data model for the database).
  2. Add a custom RIA service that will re-use the data model created by step 1 (we're using this method so you can add the equivalent of computed properties that can be searched/sorted by).

If you're not familiar with creating RIA services for consumption by LightSwitch, this article, How Do I: Display a Chart Built On Aggregated Data, will show you all that you need to know to successfully create one. Don't be put off by the fact that the article explains creating an entity specifically to illustrate aggregating data for display in a chart, the basic techniques to do what you want are the same, just ignore the part about the chart.

Your computed properties will be ordinary string properties in your RIA service (because LightSwitch will only search/sort string properties).

Because you'll be creating a custom entity with exactly the properties that you want (whether they exist in the database or not), LightSwitch will treat your computed properties like any other string property.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top