This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am a VB developer trying to evaluate LightSpeed for a new development assignment and have little to no experience with it. I also have no experience with C# and find your examples difficult to follow as a result. It would be much appreciated if you would publish your examples in both languages. I am trying to get a Dynamic Data project working with LightSpeed and don't understand the syntax in the instructions. I have created the LightSpeed model as LsModel. In step 5 you state "Declare a LightSpeedContext<TestUnitOfWork> (replacing Test with the name of your model)." What is the VB syntax for this? Then, what would the syntax be for the data provider registration in step 6? Thanks. |
|
|
Hello Steve, Sorry the C# bias makes the examples hard to follow. We'll see if we can improve this in future releases. The angle brackets <> are C# syntax for generics. So in Visual Basic this would be LightSpeedContext(Of TestUnitOfWork), e.g. Private Shared LightSpeedContext As LightSpeedContext(Of TestUnitOfWork) = New LightSpeedContext(Of TestUnitOfWork) The registration code would look something like this: model.RegisterContext( _ |
|
|
Thanks Ivan for the speedy reply. But I still don't understand how to connect it to the LightSpeed model. In the instructions you say to replace Test with the name of my model. What exactly does that mean? I created the model as "LsModel" in the project. How do I wire it up? Where does the UnitOfWork get created?
|
|
|
If you click on the background of your LightSpeed model, and look in the Properties window, you'll see a Name property, which I would expect in your case to be "LsModel". The designer uses this to create a "strongly typed unit of work" for LINQ queries (like a LINQ to SQL DataContext). This class will have the name XxxUnitOfWork, where Xxx is the name -- e.g. LsModelUnitOfWork. So where I wrote TestUnitOfWork, you would just substitute LsModelUnitOfWork: Private Shared LightSpeedContext As LightSpeedContext(Of LsModelUnitOfWork) = New .... And similarly in the line about the LightSpeedDataModelProvider. And that should be all you need to do. You don't need to worry about where the UnitOfWork gets created, because that is handled internally by Dynamic Data and the LightSpeed Web classes. When you call model.RegisterContext in Global.asax.vb, that tells Dynamic Data which data model provider to use. Dynamic Data therefore calls the LightSpeedDataModelProvider when it needs to talk to the database, and LightSpeedDataModelProvider creates the required UnitOfWork object automatically. Hope that clarifies things -- feel free to ask further if it's still not clear how it fits together! |
|
|
I already tried "LsModelUnitOfWork", before submitting the post, and VS says the type isn't defined. Aside from the C# syntax, that's what's been confusing. I checked the properties of the LS model and the name is LsModel. Any ideawhy isn't LsModelUnitOfWork defined? |
|
|
That sounds a bit odd. One possibility is that the classes are being generated into a different namespace, but if that were the case I'd be expecting VB to give you an "import namespace" smart tag. Could you open LsModel.lsmodel.vb (the generated code file; you may need to turn on Show Hidden Files to see it, I'm not sure whether Visual Basic displays dependent files by default) and search for a class with a name ending in UnitOfWork? If you find one called LsModelUnitOfWork, then it's probably a namespace issue; if it's called something else, then please let me know what; and if you don't find one at all, then we may be misdetecting your project version (we don't generate a XxxUnitOfWork if we think the project is targeting .NET 3.0 or below). Thanks! |
|
|
Found the problem. Your example is incorrect. You have the word test one too many times. Private Shared LightSpeedContext As LightSpeedContext(Of TestUnitOfWork) = New LightSpeedContext(Of TestUnitOfWork) Should be Private Shared LightSpeedContext As LightSpeedContext(Of UnitOfWork) = New LightSpeedContext(Of TestUnitOfWork) Your C# help text example is also wrong. |
|
|
Oops, I don't think what I posted is right. LsModelUnitOfWork is still invalid. |
|
|
I checked the vb code and here's what I found. <System.CodeDom.Compiler.GeneratedCode("LightSpeedModelGenerator", "1.0.0.0")> _ the namespace of Dynamic_Data is the same as my project. |
|
|
Okay, it looks like the class is defined, so I think this is a namespace issue. My guess is that the Global_asax class is being put into the top-level namespace of the project, but we are emitting a Namespace statement which is putting LsModelUnitOfWork into the Dynamic_Data namespace *within* the VB implicit project namespace.
Could you try adding an Imports Dynamic_Data and/or Imports Dynamic_Data.Dynamic_Data at the top of your Global.asax.vb please, and see if either of those improves matters? (Sorry, the only machine I have with Visual Basic on it doesn't have the LightSpeed generator on it right now, or I would try this myself.) Thanks! Regarding your suggested code, no, the Test / LsModel / Xxx prefix is required on both sides (though you can of course use type inference to save writing it out on the left hand side). LightSpeedContext(Of
XxxUnitOfWork) is not convertible to LightSpeedContext(Of UnitOfWork). This is not a LightSpeed issue but a limitation of the way the current
versions of VB and C# handle generics. |
|
|
Imports Dynamic_Data didn't work. But Imports Dynamic_Data.Dynamic_Data did. Now I am able to run the project. is this a difference between C# and VB projects? |
|
|
When I run the project and try to view a table, I get an error saying the connection string is not initialized. Any thoughts? |
|
|
Regarding the namespace, yes, this is a difference between C# and VB projects. In C#, the developer must specify all namespaces explicitly. In VB, there is an implicit project namespace which saves the developer specifying it in every file, but it means that if the developer (or a code generator) *does* specify a namespace, it gets wrapped within the implicit namespace. It looks like we should probably make it optional for the designer to specify a namespace, so that our generated classes can be emitted at the top level. Regarding the connection string, I did abbreviate the LightSpeedContext initialisation for brevity I'm afraid. Apologies for the confusion. The connection string (and certain other configuration information) must be specified as part of the LightSpeedContext, either through configuration or through code. If you right-click your model and choose Get Started then you should see a screen showing how to set up the configuration file entries and then how to reference the configuration file from code (including VB), but I'll run through both options quickly: Code To configure LightSpeed in code, when creating the LightSpeedContext, specify properties using object initialiser syntax: ... = New LightSpeedContext(Of LsModelUnitOfWork) With { _ Configuration To configure LightSpeed using the config file, add the following sections to the app.config file: <configSections> (Again remove the pluralizeTableNames setting if your table names are singular.) Then in code pass the context name to the constructor: ... = New LightSpeedContext(Of LsModelUnitOfWork)("Dev") Settings The settings you're most likely to need to address (apart from obviously the connection string and the database type) are: * Pluralize Table Names -- discussed above * Identity Method -- how IDs are allocated to objects. The default is KeyTable which requires you to create a table called KeyTable in the database. Scripts are provided for this, or you can use an alternative method such as Guid or IdentityColumn. See Help Topics > LightSpeed > Identity Generation in the help file for more info. * Quote Identifiers -- important if any of your table names are reserved words (e.g. if you have an Order table). Please see Help Topics > LightSpeed > Configuration in the help file for more info about all the settings. |
|
|
Thanks for the help. It's working now. I know this must have very remedial for you but it was very helpful to me. |
|