class Program
{
class Company
{
public string Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
class Employee
{
public string Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
// Demo the Store & SaveChanges
static void Save()
{
using (var documentStore = new DocumentStore())
{
documentStore.Url = "http://localhost:8080/";
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
session.Store(new Company { Location = "Bengaluru", Name = "MIC" });
session.Store(new Company { Location = "Virginia", Name = "TD" });
session.Store(new Employee { Location = "Bengaluru", Name = "Suresh Babu" });
session.Store(new Employee { Location = "Virginia", Name = "David Walker" });
session.SaveChanges();
}
}
}
static void Query()
{
using (var documentStore = new DocumentStore())
{
documentStore.Url = "http://localhost:8080/";
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
var companyResults = session.Query
var employeeResults = session.Query
foreach (var result in companyResults)
{
Console.WriteLine("Company Name : {0}, Location : {1}, ID : {2}", result.Name, result.Location, result.Id);
}
foreach (var result in employeeResults)
{
Console.WriteLine("Employee Name : {0}, Location : {1}, ID : {2}", result.Name, result.Location, result.Id);
}
}
}
}
static void Load()
{
using (var documentStore = new DocumentStore())
{
documentStore.Url = "http://localhost:8080/";
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
var companyResult = session.Load
var employeeResult = session.Load
Console.WriteLine("Company Name : {0}, Location : {1}, ID : {2}",
companyResult.Name, companyResult.Location, companyResult.Id);
Console.WriteLine("Employee Name : {0}, Location : {1}, ID : {2}",
employeeResult.Name, employeeResult.Location, employeeResult.Id);
companyResult = session.Load
employeeResult = session.Load
Console.WriteLine("Company Name : {0}, Location : {1}, ID : {2}",
companyResult.Name, companyResult.Location, companyResult.Id);
Console.WriteLine("Employee Name : {0}, Location : {1}, ID : {2}",
employeeResult.Name, employeeResult.Location, employeeResult.Id);
}
}
}
static void LuceneQuery()
{
using (var documentStore = new DocumentStore())
{
documentStore.Url = "http://localhost:8080/";
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
var companyResults = session.Advanced.LuceneQuery
.Where("Location:Virginia").ToArray();
var employeeResults = session.Advanced.LuceneQuery
.Where("Name:\"David Walker\"")
.WaitForNonStaleResults()
.ToArray();
foreach (var result in companyResults)
{
Console.WriteLine("Company Name : {0}, Location : {1}, ID : {2}", result.Name, result.Location, result.Id);
}
foreach (var result in employeeResults)
{
Console.WriteLine("Employee Name : {0}, Location : {1}, ID : {2}", result.Name, result.Location, result.Id);
}
}
}
}
static void CreateIndex()
{
using (var documentStore = new DocumentStore())
{
documentStore.Url = "http://localhost:8080/";
documentStore.Initialize();
documentStore.DatabaseCommands.PutIndex("EmployeeNameIndex",
new IndexDefinitionBuilder
{
Map = employees => from employee in employees
select new { employee.Name }
}
);
documentStore.DatabaseCommands.PutIndex("CompanyLocationIndex",
new IndexDefinitionBuilder
{
Map = companies => from company in companies
select new { company.Location }
}
);
}
}
static void Main(string[] args)
{
Save();
Query();
Load();
CreateIndex();
LuceneQuery();
}
}
No comments:
Post a Comment