TechTalk Genome Wire Object Protocol v4.2

<Member> Element

Specifies a property to be serialized in a view.

<View name=" view " type=" type ">
<Member name="(property|*)" />
</View>

or

<View name=" view " type=" type ">
<Member name=" property " view=" referred-view " [filter=" filter-clause "] [order=" order-expression "] />
</View>

or

<View name=" view " type=" type ">
<Member name=" property ">
<Member name=" referred-property1 " />
<Member name=" referred-property2 " />
...
</Member>
</View>
view
A name identifying the serialization view.
type
A type specifying a persistent class.
property
Public scalar, reference or Set property defined on type.
referred-view
A view name. If property is an object reference property, referred-view has to be defined on the referred type. If property is a Set, referred-view has to be defined on the element type of property.
filter-clause
An OQL implicit function. May only be defined if property is a Set.
order-expression
An OQL order expression. May only be defined if property is a Set.
referred-property1, referred-property2, ...
Public scalar, reference or Set properties. If property is an object reference property, properties has to be defined on the referred type. If property is a Set, properties has to be defined on the element type of property.

Remarks

<Member> element specifies a propety that will be serialized when a persistent instance is serialized using view. The property has to be declared on type or one of its base types. Only scalar, referential or collection (Set) properties can be specified. Multiple <Member> elements can be specifed for each view.

Specifying asterisk (*) as property name will include all scalar fields into the serialization view.

Deep serialization aspects can be defined by including referential and collection properties into the view definition. When serializing this kind of properties, the referred persistent objects (the referred object for referential and the items in the Set for collection properties) will be serialized using a specific serialization view. This view can be specified in the <Member> element by reusing an existing view definition (referred-view) or defining the referred view with sub <Member> elements. If neither referred-view nor sub <Member> elements are specified, all scalar fields will be included automatically for serializing the property.

To control which items of the referred Set for collection properties are to be serialized, a filter may be defined on the <Member> element. The filter-clause expression will be evaluated for each element of the Set. Only the items for which the filter-clause returns true will be included in the collection.

By default the order of the items in the referred Set for collection properties is indeterministic. To control this, an order-expression may be specified.

Examples

          
Animal.cs
                    
public abstract class Animal : Persistent {

    public abstract Guid Id { get; set; }
    public abstract string Name { get; set; }
    public abstract TaxonomyClass Class { get; set; }
    public abstract int Age { get; set; }
    
    public abstract Cage Cage { get; set; }
}

public abstract class Cage : Persistent {
        public abstract Guid Id { get; set; }
        public abstract string Name { get; set; }
        public abstract int Size { get; set; }

        public abstract Set Inhabitants
        {
            [return: ElementType(typeof(Animal))]
            get;
        }
}
                
          
AnimalViews.xml    
                    
<WireObjectProtocol xmlns="urn:TechTalk:Genome.Wop.Definition">
    <Using namespace="Zoo"/>

    <View name="ListItem" type="Animal">
        <Member name="Name" />
    </View>
    
    <View name="WithCage" type="Animal">
        <Member name="Name" />
        <Member name="Class" />
        <Member name="Age" />
        
        <Member name="Cage">
            <Member name="Name" />
            <Member name="Size" />
        </Member>
    </View>

    <View name="WithInhabitants" type="Cage">
        <Member name="Name" />
        <Member name="Size" />
        
        <Member name="Inhabitants" view="ListItem" order="Name ascending, Age descending"/>
    </View>
    
    <View name="WithYoungInhabitants" type="Cage">
        <Member name="Name" />
        <Member name="Size" />
        
        <Member name="Inhabitants" view="ListItem" filter="Age < 100"/>
    </View>
    
</WireObjectProtocol>
                
          
ServiceLayer.cs
                    
using Zoo;
using Zoo.Dto;                  
using Zoo.Dto.Serializers;
                    
[WebService]
public class AnimalSerivces {

    [WebMethod]
    public AnimalDto GetByName(string name) {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Animal animal = (Animal)DB.Extent(typeof(Animal))["Name = {0}", name].ToObject();
            
            // serializing the result to a DTO object with view "WithCage"
            return AnimalSerializer.SerializeWithCage(animal);
        }
    }

    [WebMethod]
    public CageDto GetCageWithAnimals(string cageName) {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Cage cage = (Cage)DB.Extent(typeof(Cage))["Name = {0}", cageName].ToObject();
            
            // serializing the result to a DTO object with view "WithInhabitants"
            return CageSerializer.SerializeWithInhabitants(cage);
        }
    }

    [WebMethod]
    public CageDto GetCageWithYoungsters(string cageName) {
        using (Context.Push(ReadOnlyContext.Create())) {
            // do some business logic
            Cage cage = (Cage)DB.Extent(typeof(Cage))["Name = {0}", cageName].ToObject();
            
            // serializing the result to a DTO object with view "WithYoungInhabitants"
            return CageSerializer.SerializeWithInhabitants(cage);
        }
    }
}
                
          
Transferred messages    
                    
<GetByNameResponse>
    <GetByNameResult xsi:type="AnimalDto">
        <Id>1</Id>
        <Name>Nemo</Name>
        <Class>Fish</Class>
        <Age>1</Age>
        <Cage>
            <Id>10</Id>
            <Name>Fishtank</Name>
            <Size>1</Size>
        </Cage>
    </GetByNameResult>
</GetByNameResponse>    

<GetCageWithAnimalsResponse>
    <GetCageWithAnimalsResult xsi:type="CageDto">
        <Id>10</Id>
        <Name>Fishtank</Name>
        <Size>1</Size>
        
        <Inhabitants>
            <AnimalDto>
                <Id>2</Id>
                <Name>Bruce</Name>
            </AnimalDto>
            <AnimalDto>
                <Id>4</Id>
                <Name>Good Ol' Crush</Name>
            </AnimalDto>
            <AnimalDto>
                <Id>1</Id>
                <Name>Nemo</Name>
            </AnimalDto>
            <AnimalDto>
                <Id>3</Id>
                <Name>Oscar</Name>
            </AnimalDto>
        </Inhabitants>
    </GetCageWithAnimalsResult>
</GetCageWithAnimalsResponse>

<GetCageWithYoungstersResponse>
    <GetCageWithYoungstersResult xsi:type="CageDto">
        <Id>10</Id>
        <Name>Fishtank</Name>
        <Size>1</Size>
        
        <Inhabitants>
            <AnimalDto>
                <Id>1</Id>
                <Name>Nemo</Name>
            </AnimalDto>
            <AnimalDto>
                <Id>2</Id>
                <Name>Bruce</Name>
            </AnimalDto>
            <AnimalDto>
                <Id>3</Id>
                <Name>Oscar</Name>
            </AnimalDto>
        </Inhabitants>
    </GetCageWithYoungstersResult>
</GetCageWithYoungstersResponse>
                

Requirements

Type: TechTalk.Genome.Wop.Definition.Builder.Xml.MemberXmlData

Assembly: TechTalk.Genome.Wop.dll

Version: 4.2.11

Editions: Professional, Community, Evaluation

See Also

<View> Element