1: [EnableClientAccess]
2: public class RootEntityService : DomainService
3: {
4: private static List<RootEntity> dataSource = new List<RootEntity>();
5:
6: public IQueryable<RootEntity> GetRootEntities()
7: {
8: var q = from r in dataSource
9: //from src in r.Child.SubChildren
10: select r;
11:
12: return q.AsQueryable();
13: }
14:
15: public IQueryable<ChildEntity> GetChildEntities(Guid parentId)
16: {
17: var q = from r in dataSource
18: where r.Id == parentId
19: select r.Child;
20:
21: return q.AsQueryable();
22: }
23:
24: public IQueryable<SubChildEntity> GetSubChildren(Guid parentId)
25: {
26: var q = from r in dataSource
27: from s in r.Child.SubChildren
28: where r.Id == parentId
29: select s;
30:
31: return q.AsQueryable();
32: }
33:
34: public IQueryable<Shape> GetShapes(Guid parentId)
35: {
36: var q = from r in dataSource
37: from sc in r.Child.SubChildren
38: where r.Id == parentId
39: select sc.Shape;
40:
41: return q.AsQueryable();
42: }
43:
44: public void InsertRootEntity(RootEntity value)
45: {
46: if (dataSource.Find(entity => entity.Id == value.Id) != null)
47: {
48: throw new InvalidOperationException("Cannot add two entities with the same key");
49: }
50:
51: dataSource.Add(value);
52: value.ChildId = value.Child.Id;
53: foreach (var sub in value.Child.SubChildren)
54: {
55: sub.ChildEntityId = value.Child.Id;
56: sub.Shape.SubChildEntityId = sub.Id;
57: }
58: }
59:
60: public void UpdateRootEntity(RootEntity value)
61: {
62: var desiredEntity = dataSource.Find(entity => entity.Id == value.Id);
63: if (desiredEntity == null)
64: {
65: throw new InvalidOperationException("The given entity is not part of the data source");
66: }
67:
68: dataSource.Remove(desiredEntity);
69: dataSource.Add(value);
70:
71: value.ChildId = value.Child.Id;
72: }
73:
74: public void DeleteEntity(RootEntity value)
75: {
76: var desiredEntity = dataSource.Find(entity => entity.Id == value.Id);
77: if (desiredEntity == null)
78: {
79: throw new InvalidOperationException("The given entity is not part of the data source");
80: }
81:
82: dataSource.Remove(desiredEntity);
83: }
84:
85: public void InsertChildEntity(ChildEntity value)
86: {
87: }
88:
89: public void UpdateChildEntity(ChildEntity value)
90: {
91: }
92:
93: public void DeleteChildEntity(ChildEntity value)
94: {
95: }
96:
97: public void InsertSubChildEntity(SubChildEntity value)
98: {
99: }
100:
101: public void DeleteSubChildEntity(SubChildEntity value)
102: {
103: }
104:
105: public void UpdateSubChildEntity(SubChildEntity value)
106: {
107: }
108:
109: public void InsertCircle(Circle circle)
110: {
111: }
112:
113: public void UpdateCircle(Circle circle)
114: {
115: }
116:
117: public void DeleteCircle(Circle circle)
118: {
119: }
120:
121: public void InsertShape(Shape Shape)
122: {
123: }
124:
125: public void UpdateShape(Shape Shape)
126: {
127: }
128:
129: public void DeleteShape(Shape Shape)
130: {
131: }
132:
133: public override System.Collections.IEnumerable Query(QueryDescription queryDescription, out IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> validationErrors, out int totalCount)
134: {
135: return base.Query(queryDescription, out validationErrors, out totalCount);
136: }
137:
138: public override bool Submit(ChangeSet changeSet)
139: {
140: return base.Submit(changeSet);
141: }
142:
143: public override void Initialize(DomainServiceContext context)
144: {
145: base.Initialize(context);
146: }
147:
148: public override object Invoke(DomainOperationEntry operation, object[] parameters, out IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> validationErrors)
149: {
150: return base.Invoke(operation, parameters, out validationErrors);
151: }
152:
153: protected override bool AuthorizeChangeSet(ChangeSet changeSet)
154: {
155: return base.AuthorizeChangeSet(changeSet);
156: }
157:
158: protected override bool ExecuteChangeSet(ChangeSet changeSet)
159: {
160: return base.ExecuteChangeSet(changeSet);
161: }
162:
163: protected override bool ValidateChangeSet(ChangeSet changeSet)
164: {
165: return base.ValidateChangeSet(changeSet);
166: }
167:
168: protected override bool PersistChangeSet(ChangeSet changeSet)
169: {
170: return base.PersistChangeSet(changeSet);
171: }
172:
173: protected override bool ResolveChangeSet(ChangeSet changeSet)
174: {
175: return base.ResolveChangeSet(changeSet);
176: }
177:
178: protected override bool Resolve(object current, object original, object store, ResolveOption resolveOption)
179: {
180: return base.Resolve(current, original, store, resolveOption);
181: }
182:
183: protected override int Count<T>(IQueryable<T> query)
184: {
185: return base.Count<T>(query);
186: }
187:
188: protected override void OnError(DomainServiceErrorInfo errorInfo)
189: {
190: base.OnError(errorInfo);
191: }
192: }