Specifies a property to be serialized in a view.
or
or
<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.
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>
Type: TechTalk.Genome.Wop.Definition.Builder.Xml.MemberXmlData
Assembly: TechTalk.Genome.Wop.dll
Version: 4.2.4
Editions: Professional, Community, Evaluation