6 // Atsushi Enomoto <atsushi@ximian.com>
\r
7 // Pablo Íñigo Blasco <pibgeus@gmail.com>
\r
9 // Copyright (C) 2008 Novell, Inc.
\r
13 // Permission is hereby granted, free of charge, to any person obtaining
\r
14 // a copy of this software and associated documentation files (the
\r
15 // "Software"), to deal in the Software without restriction, including
\r
16 // without limitation the rights to use, copy, modify, merge, publish,
\r
17 // distribute, sublicense, and/or sell copies of the Software, and to
\r
18 // permit persons to whom the Software is furnished to do so, subject to
\r
19 // the following conditions:
\r
21 // The above copyright notice and this permission notice shall be
\r
22 // included in all copies or substantial portions of the Software.
\r
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
35 using System.Collections.Generic;
\r
39 namespace System.Data.Linq
\r
41 namespace DbLinq.Data.Linq
\r
44 public struct EntityRef<TEntity> where TEntity : class
\r
46 private TEntity entity;
\r
47 private bool hasLoadedOrAssignedValue;
\r
48 private IEnumerable<TEntity> source;
\r
50 public EntityRef(TEntity entity)
\r
53 this.entity = entity;
\r
54 hasLoadedOrAssignedValue = true;
\r
57 public EntityRef(IEnumerable<TEntity> source)
\r
59 this.source = source;
\r
60 hasLoadedOrAssignedValue = false;
\r
64 public EntityRef(EntityRef<TEntity> entityRef)
\r
66 this.entity = entityRef.entity;
\r
67 if (entityRef.entity == null && entityRef.source is ICloneable)
\r
69 source = (IEnumerable<TEntity>)((ICloneable)entityRef.source).Clone();
\r
73 hasLoadedOrAssignedValue = entityRef.hasLoadedOrAssignedValue;
\r
76 public TEntity Entity
\r
80 if (source != null) {
\r
81 foreach (var s in source) {
\r
83 throw new InvalidOperationException ("Sequence contains more than one element");
\r
93 hasLoadedOrAssignedValue = true;
\r
97 public bool HasLoadedOrAssignedValue
\r
101 return hasLoadedOrAssignedValue;
\r