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
|
Hello again - I don't know why this is proving to be so hard for me to grasp, but I'm still struggling to understand how to make all this work. Given that I have 2 tables, Master and Sub, with a FK relationship so that Sub.MasterID maps to Master.MasterID. This creates a collection of Subs on the Master, so the non-DTO entity Master appears to have a collection of Subs as part of the Entity. This I get, and you all do a great job here. However, when I want to ship these Entities via WCF to the Client app, the relationships are lost. Now I have a MasterDto object with no SubDtos. Even if I manage to traverse the Subs collection and ship that as part of the message, I still seemingly end up with separate, unrelated objects (I don't even have the MasterID to relate things manually without jumping through hoops to pass it back and forth.) I have seen some talk of WCF RIA services and what that might do to address the issue, but as far as I can tell you don't support that yet. What can I do in the meantime to pass related collections and entities back and forth across the WCF "boundary"? Do you have a sample that addresses this? Your DTOs sample takes the easy way out and avoids the issue altogether...
Thanks for the assistance, Dave |
|
|
Hi Dave, Our DTO templates dont generate any properties for associations, primarily because this would lead to a default position of large graphs being sent over the network when passing around entities (due to the serializer wanting to eagerly load the association data) so this could quickly lead to degraded performance so we wanted this to be a clearly considered addition on your part. You can add this back in by simply manipulating your DTOs, either by using partial classes or updating the generation templates, to add the associated collection properties you want to map, and then updating the corresponding mapping functions to traverse those associations. e.g. if we were altering the DTO sample to ship CartItem's along with the Cart instances, we might update CartDto to add the following property: [System.Runtime.Serialization.DataMember] and update the CopyCart(entity,dto) method to include: dto.Items = new CartItemDto[entity.Items.Count]; for (int i = 0; i < entity.CartItems.Count; i++) { dto.CartItems[i] = entity.CartItems[i].AsDto(); }
Jeremy |
|
|
5 months later, after an excursion into hardware land, I am back working on this project.
In the example above, the CopyCart(entity, dto) method is a private static method, not a partial method. Are you saying I need to make changes to the generated code in model.cs? If I modify that code, won't it get overwritten if I change the model and regenerate the mappings? I find it hard to believe, as well thought out as the rest of the platform is, that this is the preferred way to modify the functionality, especially when many people will want to do just what I am doing. You mention changing the generation templates, is that different from the example? Or, can I convert the CopyCart() method to a partial method? I can make this work, but it seems unnecessarily brittle to me. Isn't there a better way?
Thanks, Dave |
|
|
Hi Dave, Welcome back :-) There are two options here: If you are comfortable with WCF We agree that that distributed scenarios could be handled better in LightSpeed. DTO's we a first cut and got the job done initially however we did hear loud and clear that folks wanted something better. Improving distributed scenarios is a key focus of LightSpeed 4 and we recently released the beta for this and you have access to it from your account page. The reason I suggest you'll want to be comfortable with WCF is that the documentation is light at the moment and if you're not comfortable with WCF it could be a pain getting started. Effectively LightSpeed 4 won't generate DTO's by default, we're pushing distributed entities approach. Entities are fully serializable and can be sent over the wire. We've included a DistributedUnitOfWork to make life easier for pushing change sets around to allow for easier persistence in a distributed environment and much more. You can read more about this here however it's not a detailed developer guide. If you aren't comfortable with WCF Stick with the DTO approach. Unfortunately you will need to alter the templates to do what you want - keep in mind you can copy the templates locally to your solution so that you don't accidentally lose your changes when upgrading LightSpeed. I hope that helps - I only wish we had the LightSpeed 4 approach better documented for you at this time! |
|
|
One other question. This is great for shipping (reading) a collection of CartItems along with their respective Cart as DTOs, but what about adding / updating the Cart along with its respective CartItems from the DTOs created / modified by the application? I can see where I maybe could do this if the Cart existed, and I shipped the CartId along with the DTO, then returned that CartId and used it as the foreign key in new CartItem records, but that all should be handled behind the scenes, right? And what if all the members in the hierarchy (Cart and CartItems) are all new, and there are no IDs to use? Could you please give me a quick example on how to do this going the other direction? Your examples all seem to skip over this point (updating the model from DTOs), and it is very confusing for the novice...
Thanks again, Dave |
|
|
To add to the "If you aren't comfortable with WCF" part of JD's comments: There's more information about altering the templates here: http://www.mindscapehq.com/blog/index.php/2009/09/16/customising-lightspeed-entity-templates/ One thing to bear in mind is if you have a small number of DTOs that need IDs, it may be more cost-effective just to add the ID into the DTO by hand, using partial classes and partial methods as described here: http://www.mindscapehq.com/forums/Thread.aspx?PostID=9049 This will avoid the need to edit and maintain templates. Note you will do this in a PARTIAL file: do NOT change the generated code in model.cs! Regarding the update direction, the key is the CopyTo extension method which copies an incoming DTO into an entity. Thus, for update, assuming you have added an Id field to WidgetDto, your service will do something like this: void ApplyChanges(WidgetDto dto) { (If you haven't added an ID field, you can send the ID out of band: void ApplyChanges(int widgetId, WidgetDto newValues) { ... }.) For an add, you would do something similar but using new instead of FindById: int Add(WidgetDto dto) { Note that in this case your client should NOT populate your DTO's ID field because the ID will be assigned by LightSpeed -- indeed this is why the generated DTOs don't contain an Id field. |
|
|
I guess you can ignore the next question, as your answer applies to both. We are using WCF for this project, and although I am not all that familiar with it (just learning WCF for this project), it is definitely my preferred approach. So the next questions are 1) when do you expect LS 4 to be out of beta? and 2) do we need to renew our licenses to get the next version? (we've barely even gotten the shrinkwrap off of version 3...) Thanks for the great product and support! Dave |
|
|
We still have a bunch of features to add to LightSpeed 4 before we'll call it done - not to mention the documentation and samples effort to complete. This could take a wee while unfortunately. Your subscription runs until late July. You get all updates for the duration of your subscription including major versions so you don't need to worry about LightSpeed 4, you'll get it for free as part of your subscription :-) |
|
|
Thanks! One more question -- if I install the beta, will that overwrite the release insatllation, or can I run them side by side (v3 for one project and v4 in another, experimental project)? What do I need to watch out for if I try the second approach, if it's even possible?
Thanks again, Dave |
|
|
I think some things may have changed since the blog was written? I went to the first blog concerning the templates, and the blog calims "If the project contains a LightSpeed model (a .lsmodel file), you’ll see an extra entry here called LightSpeed Template File." I see no such entry, nothing at all for LightSpeed. I am running VS2010, .NET 3.5 and the Sample - DTOs solution. Under Model Project Properties I see only Misc, containing Project File and Project Folder. Does this only wotk with earlier versions of Visual Studio? What may I be missing? Dave |
|
|
I found I needed to open the .lsmodel file before the LightSpeed Template File option would appear. Once I did that it was fine (using VS2010). |
|
|
Yep, that works. Thanks, Ivan. |
|