예제 #1
0
 /// <summary>
 /// Set the current state of this dataobject to be the set of triples provided.
 /// </summary>
 /// <param name="triples">Dataobject state</param>
 /// <param name="asNewTriples">Also add the triples to the list of new triples on the context store</param>
 /// <param name="enforceClassUniqueConstraint">Add update preconditions to ensure that the update fails if the store already contains
 /// a resource with the same identity and the same rdf:type(s) as this data object.</param>
 internal bool BindTriples(IEnumerable <Triple> triples, bool asNewTriples = false, bool enforceClassUniqueConstraint = false)
 {
     if (_isLoaded)
     {
         // We are rebinding an existing data object due to a refresh
         var updateTriples = triples.ToList();
         if (updateTriples.Count == 0)
         {
             // The store has no triples for this subject
             return(false);
         }
         _triples = updateTriples;
         if (asNewTriples)
         {
             _store.AddTriples.AddRange(_triples);
             if (enforceClassUniqueConstraint)
             {
                 _store.SetClassUniqueConstraints(
                     Identity,
                     _triples.Where(
                         x => x.Predicate.Equals(TypeDataObject.Identity) && x.Subject.Equals(Identity)).Select(x => x.Object));
             }
         }
         return(true);
     }
     _triples = triples.ToList();
     if (asNewTriples)
     {
         _store.AddTriples.AddRange(_triples);
         if (enforceClassUniqueConstraint)
         {
             _store.SetClassUniqueConstraints(
                 Identity,
                 _triples.Where(
                     x => x.Predicate.Equals(TypeDataObject.Identity) && x.Subject.Equals(Identity))
                 .Select(x => x.Object));
         }
     }
     _isLoaded = true;
     return(true);
 }