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
|
Howdy All, First off, I'm a total newbie, when it comes to LightSpeed... This is my first try at evaluating the product... Here's my problem... I have two tables that I would like to update via LightSpeed... They both have in them a field/column that is a sequence. The Sequences are two separate ones: Table 1: T_REF_P4P_DATA Table 2: T_CNV_MEASURE I gather that I have to set the Context identityMethod to "MultiSequence", and I've done that in my app.config file... Now fortunately, I don't have to update the two table at the same time in the code, so I can do them separately which might help... What all do I have to do to get LightSpeed to handle this??? I've seen something about setting up a NamingStategy... Do I have to do this? and if so, where do I do this inside or outside of the using block for my UnitOfWork??? I've also seen something about setting up some GetMultiSequenceName ... I also saw something about running the Sequence.sql script in the "Mindscape\LightSpeed\Providers\Oracle9" folder??? do I have to run that??? Everything I've seen, either in the "Help" file or out on these forums have said that I need to implement this or that, but neither have been very clear as to what all I need to do to do that "implementation"... For instance: quote from the "Help" file: "You can also use multiple sequences by selecting the MultiSequence identity method. This supports “sequence per table” conventions. In this case, you must implement INamingStrategy, and return the per-table name from INamingStrategy.GetMultiSequenceName. See Configuration or LightSpeedContext.NamingStrategy for how to apply your custom naming strategy." However, when I look at either "Configuration" or the "LightSpeedContext.NamingStrategy" there is nothing explaining what code I need to write... Is there any sort of clear and COMPLETE example from start to finish of code that I could look at??? everything I've seen is little code snippets and not very clear. I think LightSpeed is a cool product and that I would like to use it for many of my projects... However, I can't make sense of it...
Thanks in advance, |
|
|
Hello Kevin, Sorry this has proved confusing: we'll look at improving that documentation and maybe providing a sample for this. In the meantime, have a look at this: http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=1988&PostID=6561 This should give you a slightly clearer idea of how the naming strategy fits in and how you might implement it. (A slightly more sophisticated example of implementing the naming strategy is at http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=1988&PostID=7727.) The sequence.sql script is required only if you are using the LightSpeed default sequence (the Sequence identity method). Since you are using your own sequences, you do NOT need to run this script. However please also see http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=1988&PostID=7739 which discusses some configuration considerations around the IdentityBlockSize setting and sequences. Hope this helps -- please let us know if it is still confusing or if you need further assistance or examples! |
|
|
Hey Ivan, I follow most of what you said, and I've looked at the two threads that you mentioned... What I've done is created a class for each table's NamingStrategy. In those classes I've implemented the following:
class P4PDataNamingStrat : INamingStrategy And so on for the other table as well... Now in my main program I need to set the context's NamingStrategy to a instance on whioch ever class I'm updating at the time correct? Now for the hard part... I'm following the screencast example and have created a "Repository" class to set up the context ... Here's the code for the Repository class: public static class Repository So... My question is... How do I go about setting the Repository's context's NamingStrategy to an instance of either of my tweo new classes??? Or do I do away with the whole "Repository" concept all together??? and just deal with a context by itself??? Thanks again, Kevin Orcutt
|
|
|
Okay, I think I see the confusion. The naming strategy is a context-level thing, not a table-level thing. You should have only one naming strategy, and it should be able to handle all of your tables. (Think of it as a database-wide policy or a convention, rather than a handler for a particular table.) You'll use the entityType argument to handle this. For example: public string GetMultiSequenceName(string defaultName, Type entityType) { Now this implementation is going to be too naive for you, because your sequence names don't (from your examples) follow a predictable naming convention. So you need to find some way of capturing all that irregular per-table info, so that you can hide the irregularity behind the "database-wide policy" facade of INamingStrategy. One possible solution is to create a custom attribute and apply it to your entity classes: public class SequenceNameAttribute : Attribute { [SequenceName("MEASURE_SEQ")] [SequenceName("REF_P4P_ID_SEQ")] Then your naming strategy would do this: public string GetMultiSequenceName(string defaultName, Type entityType) { (Error handling omitted.) Now you're got a single naming strategy that you can apply at a context level, either via the namingStrategyClass configuration file entry or by setting it directly on the _context object when you create it. No need to muck around swapping strategies "just in time." Attributes aren't the only way to handle this, e.g. you could store the table-to-sequence mapping in a configuration file, etc. But hopefully it gives you the general idea! |
|
|
Ok Ivan, I'm still following your lead... When you setup the partial classes... should that be on the classes defined in the Model or are they new classes? The Model setup the two classes: TCnvMeasure and TRefP4PDatum as my two classes for the tables, and your example created the two partial classes: [quote user="ivan"] [SequenceName("MEASURE_SEQ")]
[SequenceName("REF_P4P_ID_SEQ")] So now later on in my main code... which class types do I use for my variable ??? TRefP4PDatum or RefP4P??? I thinking that the SequenceNameAttribute definitions should go on the classes defined in the Model, but I could very well be wrong here :-) And, is there a particular place I need to place the attribute partial classes, or can I place them in the namespace before my main program class??? Thanks in advance!!! Kevin Orcutt |
|
|
Absolutely right: the attributes should go on the classes defined on the model. But you can't apply them in the C# code generated by the designer, because that gets overwritten every time you update the model. Hence the need to create partial class declarations. My class names "RefP4p" and "Measure" were *guesses* at your class names. If your model class is called TRefP4PDatum, then that's the name you need to give in the partial class declaration, and that's the class type you use for your variable: ignore my guesses at the names. The purpose of the partial class declaration is to *extend* your existing entity class defined in the model, *not* to create a whole new class. So if your model class is called TRefP4PDatum, then you'd write this: [SequenceName("REF_P4P_ID_SEQ")] And similarly for TCnvMeasure. The location and layout of the partial class declarations doesn't matter, but they do need to be in the same namespace as the generated class definitions. (Otherwise C# will regard them as different classes. If you're not sure what this namespace is, expand the .lsmodel file in Solution Explorer, open the .cs file that you find underneath it, and look at the namespace declaration in that.) For a test or trial you could put them in the same file as your program class, but I'd suggest creating a separate file for them, perhaps called SequenceInfo.cs or ModelExtensions.cs, and put them in there -- this will make it easier to find as your project grows. |
|