Gus
Gus

Reputation: 10659

Visual Studio LightSwitch - How to run query on Application start-up from code?

I have a database containing tables related to user security and I imported this database into LightSwitch into a data source called UserData. I've then added a query off one of the entities (Role entity) - GetRolesByPersonId(int). I see that this query is generated as a non-static method of the UserData class, and, in order to call it, I of course need an instance of this class.

I would like to run this query as my application starts up to get security-related information in order to enable/disable menus.

Question 1: From what method/event should I read the query? I trying from Application_Initialize(), am I correct?

Question 2: Is there a ready-to-use instance of UserData at the time of Application_Initialize()? Do I need to instanciate a new object in order to call my query?

Thanks

Upvotes: 0

Views: 1165

Answers (1)

hgminerva
hgminerva

Reputation: 206

I think you can use Me.CreateDataWorkspace.ApplicationData in the Application_Initialize().

Upvotes: 1

Related Questions