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
|
Hi, I am using Lightspeed 3.0 and I am trying to create and xml Export file from my DB. So I am trying to implement a function where I create an xml node for each of my objects and then for each of the EntityProperties for that object I need to create an xml attribute. I want to do this generically so I don't need to maintain it, should we choose to add new properties to any of the entities. My issue is that say I have an entity called a customer with two EntityProperties - Name and Telephone. And then I have another object called orders which has a one to many relationship with customer. A customer object then will have then 3 properties - Name, Telephone and also Orders. ONly Name and Telephone however are EntityProperties. From my code how can I get a list back from an entity with it's EntityProperties only(not all properties). I looked through the API and could not find anything.
Thanks Susan
|
|
|
This is not directly possible at runtime because the CLR doesn't know which properties are "entity" properties and which are not. LightSpeed does internally have a model of which fields are persistent but this is not exposed through the API. If you are using designer-generated clases then you could use reflection to pick out the field name constants and use those. For example, if you have an entity property named "Name", the designer generates public const string NameField = "Name"; Therefore you could use reflection to get all public constants of type string, and select the ones whose name ends in "Field." This is somewhat heuristic because you could add other "XxxField" constants in the partial class but it's probably the best you'll get using pure runtime data. Be aware that this will also pick up foreign key properties, because those are indistinguishable from other entity properties at runtime. If you need something more precise then the only thing I can think of is to load the .lsmodel file into a XmlDocument or XDocument and select out the entity properties using XPath or LINQ to XML. However, even this can be defeated if you have properties with Generation set to None or FieldOnly and you have used a different name for the manually implemented property. |
|
|
Thanks very much for the quick reply. The last suggestion to load the model file might actually work for us. I will give it a try to morrow and let u know if I hit any roadblocks. Thanks Again Susan |
|