Esempio n. 1
0
        /// <summary>
        /// Updates the properties of a resource in the backing RDF store.
        /// </summary>
        /// <param name="resource">Resource that is to be updated in the backing store.</param>
        /// <param name="transaction">Transaction associated with this action.</param>
        public virtual void UpdateResource(Resource resource, ITransaction transaction = null)
        {
            string updateString;

            if (resource.IsNew)
            {
                updateString = string.Format(@"WITH {0} INSERT {{ {1} }} WHERE {{}}",
                                             SparqlSerializer.SerializeUri(Uri),
                                             SparqlSerializer.SerializeResource(resource, IgnoreUnmappedProperties));
            }
            else
            {
                updateString = string.Format(@"WITH {0} DELETE {{ {1} ?p ?o. }} INSERT {{ {2} }} WHERE {{ OPTIONAL {{ {1} ?p ?o. }} }}",
                                             SparqlSerializer.SerializeUri(Uri),
                                             SparqlSerializer.SerializeUri(resource.Uri),
                                             SparqlSerializer.SerializeResource(resource, IgnoreUnmappedProperties));
            }

            SparqlUpdate update = new SparqlUpdate(updateString)
            {
                Resource = resource
            };

            ExecuteUpdate(update, transaction);

            resource.IsNew          = false;
            resource.IsSynchronized = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the properties of a resource in the backing RDF store.
        /// </summary>
        /// <param name="resource">Resource that is to be updated in the backing store.</param>
        /// <param name="transaction">ransaction associated with this action.</param>
        public void UpdateResource(Resource resource, ITransaction transaction = null)
        {
            string updateString;

            if (resource.IsNew)
            {
                updateString = string.Format(@"WITH {0} INSERT {{ {1} }} WHERE {{}}",
                                             SparqlSerializer.SerializeUri(Uri),
                                             SparqlSerializer.SerializeResource(resource));
            }
            else
            {
                updateString = string.Format(@"WITH {0} DELETE {{ {1} ?p ?o. }} INSERT {{ {2} }} WHERE {{ {1} ?p ?o. }} ",
                                             SparqlSerializer.SerializeUri(Uri),
                                             SparqlSerializer.SerializeUri(resource.Uri),
                                             SparqlSerializer.SerializeResource(resource));
            }

            SparqlUpdate update = new SparqlUpdate(updateString);

            update.Resource = resource;

            ExecuteUpdate(update, transaction);

            resource.IsNew = false;
        }