如何通过使用LINQtoSPARQL编写基于linq的服务来连接数据库?

时间:2018-12-12 10:25:23

标签: sparql graphdb dotnetrdf

以下是TestDataProvidergithublinkk)中LINQtoSPARQL类的代码。这里,数据取自字符串或文件。

namespace LINQtoSPARQLSpace.Tests
{
public static class TestDataProvider
{
    public static ISPARQLQueryable<T> GetQuerable<T>(string data, 
        bool autoquotation = true, 
        bool treatUri = true,
        IEnumerable<Prefix> prefixes = null,
        bool skipTriplesWithEmptyObject = false,
        bool mindAsterisk = false,
        bool useStore = false,
        string defaultGraphUri = "http://test.org/defaultgraph")
    {
        DynamicSPARQLSpace.dotNetRDF.Connector connector = null;

        if (useStore)
        {
            var store = new VDS.RDF.TripleStore();
            store.LoadFromString(data);
            connector = new Connector(new InMemoryDataset(store, new Uri(defaultGraphUri)));

        }
        else
        {
            var graph = new VDS.RDF.Graph();
            graph.LoadFromFile(data);
            connector = new Connector(new InMemoryDataset(graph));
        }


        dynamic dyno = DynamicSPARQL.CreateDyno(connector.GetQueryingFunction(), 
            updateFunc: connector.GetUpdateFunction(),
            autoquotation: autoquotation,
            treatUri: treatUri,
            prefixes:prefixes,
            skipTriplesWithEmptyObject:skipTriplesWithEmptyObject,
            mindAsterisk:mindAsterisk);

        return new SPARQLQuery<T>(dyno);
    }
}
}

现在,我想连接我的数据库(GraphDB ontext)。现在,我可以借助以下几行来连接数据库:

Options.ForceHttpBasicAuth = true;
var store2 = new VDS.RDF.Query.SparqlRemoteEndpoint(new Uri("http://localhost:7200/repositories/786"));      
store2.SetCredentials("admin", "admin");

现在,如何将这个SparqlRemoteEndpoint对象传递给Connector类对象?我要以正确的方式进行连接吗?

请帮助。

0 个答案:

没有答案