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, I had difficulty trying to follow JB's post http://www.mindscape.co.nz/blog/index.php/2009/01/20/lightspeed-wcf-and-serialization/ as I can't seem to find the Convertor function he referrs to. So the code EmployeeDTO[] allEmployees = unitOfWork.Find<employee>().ToArray(DTOConvertor.ConvertEmployee); doesn't work. For starters there's no .ToArray() option on my query result. I believe it has to be cast to a List<T> as IList<T> does not have a .ToArray method on it? Anyway I wrote an extension method for a specific IList<MyEntity> called IList<Client>. Thing is, if you wanted to write a generic extension method to convert IList<Entity> to something like EntityDto[] I don't think you can, because (as in my example) ClientDto inherits off of a custom code-generated class (in my case, "FSSQlModelDtoBase"). Could you please add an specifically named Interface or something to also inherit off of. Here is the code: public static class ClientExtensions |
|
|
ToArray is an extension method on IEnumerable<T> (and therefore on IList<T>). You will need to have a "using System.Linq;" statement to bring it into scope. So your second method shouldn't be necessary: just call listOfEntities.ToArray(). I'm not quite sure what you're asking for with your comment about adding "a specifically named interface or something to also inherit off of." Are you asking for an interface to be implemented by all generated DTO classes? By the generated DTO base class? (If the latter, you can do this yourself via the partial class.) What members do you need in this interface, and how should the generated classes implement them? Sorry if I am missing something obvious here... |
|
|
Hello, I have been using the static partial void AfterCopy[EntityName]([EntityName] entity, [EntityName]Dto dto) thing in the generated code - more appropriately I have made my own partial methods. Turns out you cannot implement a static partial method of both "AfterCopy[EntityName] entity, dto" as well as "AfterCopy[EntityName] dto, entity". Resharper tells me "A partial method may not have multiple implementing declarations".??? Well the model still builds and my project runs so I guess its a resharper bug? Thanks, |
|