SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Conhecendo RavenDB
Elemar Júnior
@elemarjr
elemarjr@ravendb.net
elemarjr@gmail.com
elemarjr.com
Olá, eu sou Elemar Jr
...
RavenDB
Mas, vamos falar de
@ayende
{
"Company": "companies/86",
"Employee": "employees/4",
"OrderedAt": "1996-11-07T00:00:00.0000000",
"RequireAt": "1996-12-05T00:00:00.0000000",
"ShippedAt": "1996-11-15T00:00:00.0000000",
"ShipTo": {
"Line1": "Adenauerallee 900",
"Line2": null,
"City": "Stuttgart",
"Region": null,
"PostalCode": "70563",
"Country": "Germany"
},
"ShipVia": "shippers/2",
"Freight": 0.78,
"Lines": [
{
"Product": "products/1",
"ProductName": "Chai",
"PricePerUnit": 14.4,
"Quantity": 15,
"Discount": 0.15
},
{
"Product": "products/23",
"ProductName": "Tunnbröd",
"PricePerUnit": 7.2,
"Quantity": 25,
"Discount": 0
}
]
}
using Raven.Client.Document;
namespace Northwind
{
class Program
{
static void Main()
{
var documentStore = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "Northwind"
};
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
var p = session.Load<dynamic>("products/1");
System.Console.WriteLine(p.Name);
}
}
}
}
public class Product
{
public string Name { get; set; }
public string Supplier { get; set; }
public string Category { get; set; }
public string QuantityPerUnit { get; set; }
public float PricePerUnit { get; set; }
public int UnitsInStock { get; set; }
public int UnitsOnOrder { get; set; }
public bool Discontinued { get; set; }
public int ReorderLevel { get; set; }
}
using Raven.Client.Document;
namespace Northwind
{
class Program
{
static void Main()
{
var documentStore = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "Northwind"
};
documentStore.Initialize();
using (var session = documentStore.OpenSession())
{
var p = session.Load<Product>("products/1");
System.Console.WriteLine(p.Name);
}
}
}
}
public static class DocumentStoreHolder
{
private static readonly Lazy<IDocumentStore> LazyStore =
new Lazy<IDocumentStore>(() =>
{
var store = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "Northwind"
};
return store.Initialize();
});
public static IDocumentStore Store =>
LazyStore.Value;
}
string categoryId;
using (var session = DocumentStoreHolder.Store.OpenSession())
{
var newCategory = new Category
{
Name = "My New Category",
Description = "Description of the new category"
};
session.Store(newCategory);
categoryId = newCategory.Id;
session.SaveChanges();
}
using (var session = DocumentStoreHolder.Store.OpenSession())
{
var storedCategory = session
.Load<Category>(categoryId);
storedCategory.Name = "abcd";
session.SaveChanges();
}
using (var session = DocumentStoreHolder.Store.OpenSession())
{
session.Delete(categoryId);
session.SaveChanges();
}
Product[] products = session.Load<Product>(new[] {
"products/1",
"products/2",
"products/3"
});
var p = session
.Include<Product>(x => x.Category)
.Load(1);
var c = session.Load<Category>(p.Category);
var order = session
.Include<Order>(o => o.Company)
.Include(o => o.Employee)
.Include(o => o.Lines.Select(l => l.Product))
.Load("orders/1");
{
"Company": "companies/86",
"Employee": "employees/4",
"OrderedAt": "1996-11-07T00:00:00.0000000",
"RequireAt": "1996-12-05T00:00:00.0000000",
"ShippedAt": "1996-11-15T00:00:00.0000000",
"ShipTo": {
"Line1": "Adenauerallee 900",
"Line2": null,
"City": "Stuttgart",
"Region": null,
"PostalCode": "70563",
"Country": "Germany"
},
"ShipVia": "shippers/2",
"Freight": 0.78,
"Lines": [
{
"Product": "products/1",
"ProductName": "Chai",
"PricePerUnit": 14.4,
"Quantity": 15,
"Discount": 0.15
},
{
"Product": "products/23",
"ProductName": "Tunnbröd",
"PricePerUnit": 7.2,
"Quantity": 25,
"Discount": 0
}
]
}
var order = session
.Include<Order>(o => o.Company)
.Include(o => o.Employee)
.Include(o => o.Lines.Select(l => l.Product))
.Load("orders/1");
private static void QueryCompanyOrders(int companyId)
{
using (var session = DocumentStoreHolder.Store.OpenSession())
{
var orders = (
from order in session.Query<Order>()
.Include(o => o.Company)
where order.Company == $"companies/{companyId}"
select order
).ToList();
var company = session.Load<Company>(companyId);
if (company == null)
{
WriteLine("Company not found.");
return;
}
WriteLine($"Orders for {company.Name}");
foreach (var order in orders)
{
WriteLine($" {order.Id} - {order.OrderedAt}");
}
}
}
var orders = (
from order in session.Query<Order>()
where order.Company == "companies/1"
orderby order.OrderedAt
select order
).ToList();
var results = new List<Order>();
foreach (var o in GetDocumentsFor("Orders"))
{
if (o.Company == "companies/1")
results.Add(o);
}
var orderedResults = results.Sort((a, b) => a.OrderedAt.CompareTo(b.OrderedAt));
public class Employees_ByFirstAndLastName : AbstractIndexCreationTask<Employee>
{
public Employees_ByFirstAndLastName()
{
Map = (employees) =>
from employee in employees
select new
{
FirstName = employee.FirstName,
LastName = employee.LastName
};
}
}
public class People_Search : AbstractMultiMapIndexCreationTask<People_Search.Result>
{
public class Result
{
public string SourceId { get; set; }
public string Name { get; set; }
public string Type { get; set; }
}
public People_Search()
{
AddMap<Company>(companies =>
from company in companies
select new Result
{
SourceId = company.Id,
Name = company.Contact.Name,
Type = "Company's contact"
}
);
...
AddMap<Supplier>(suppliers =>
from supplier in suppliers
select new Result
{
SourceId = supplier.Id,
Name = supplier.Contact.Name,
Type = "Supplier's contact"
}
);
AddMap<Employee>(employees =>
from employee in employees
select new Result
{
SourceId = employee.Id,
Name = $"{employee.FirstName} {employee.LastName}",
Type = "Employee"
}
);
...
Index(entry => entry.Name, FieldIndexing.Analyzed);
Store(entry => entry.SourceId, FieldStorage.Yes);
Store(entry => entry.Name, FieldStorage.Yes);
Store(entry => entry.Type, FieldStorage.Yes);
}
}
public static IEnumerable<People_Search.Result> Search(
IDocumentSession session,
string searchTerms
)
{
var results = session.Query<People_Search.Result, People_Search>()
.Search(r => r.Name, searchTerms, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards)
.ProjectFromIndexFieldsInto<People_Search.Result>()
.ToList();
return results;
}
static void Main(string[] args)
{
Console.Title = "Multi-map sample";
using (var session = DocumentStoreHolder.Store.OpenSession())
{
while (true)
{
Console.Write("nSearch terms: ");
var searchTerms = Console.ReadLine();
foreach (var result in Search(session, searchTerms))
{
Console.WriteLine($"{result.SourceId}t{result.Type}t{result.Name}");
}
}
}
}
public class Products_ByCategory : AbstractIndexCreationTask<Product, Products_ByCategory.Result>
{
public class Result
{
public string Category { get; set; }
public int Count { get; set; }
}
public Products_ByCategory()
{
Map = products =>
from product in products
select new
{
Category = product.Category,
Count = 1
};
Reduce = results =>
from result in results
group result by result.Category into g
select new
{
Category = g.Key,
Count = g.Sum(x => x.Count)
};
}
}
public class Employees_SalesPerMonth :
AbstractIndexCreationTask<Order, Employees_SalesPerMonth.Result>
{
public class Result
{
public string Employee { get; set; }
public string Month { get; set; }
public int TotalSales { get; set; }
}
public Employees_SalesPerMonth()
{
}
}
Map = orders =>
from order in orders
select new
{
order.Employee,
Month = order.OrderedAt.ToString("yyyy-MM"),
TotalSales = 1
};
Reduce = results =>
from result in results
group result by new
{
result.Employee,
result.Month
}
into g
select new
{
g.Key.Employee,
g.Key.Month,
TotalSales = g.Sum(x => x.TotalSales)
};
using (var session = DocumentStoreHolder.Store.OpenSession())
{
var query = session
.Query<Employees_SalesPerMonth.Result, Employees_SalesPerMonth>()
.Include(x => x.Employee);
var results = (
from result in query
where result.Month == "1998-03"
orderby result.TotalSales descending
select result
).ToList();
foreach (var result in results)
{
var employee = session.Load<Employee>(result.Employee);
Console.WriteLine($"{employee.FirstName} {employee.LastName} made
{result.TotalSales} sales.");
}
}
public class Products_ByCategory : AbstractIndexCreationTask<Product, Products_ByCategory.Result>
{
public class Result
{
public string Category { get; set; }
public int Count { get; set; }
}
public Products_ByCategory()
{
Map = products =>
from product in products
let categoryName = LoadDocument<Category>(product.Category).Name
select new
{
Category = categoryName,
Count = 1
};
Reduce = results =>
from result in results
group result by result.Category into g
select new
{
Category = g.Key,
Count = g.Sum(x => x.Count)
};
}
}
public class Products_ProductAndSupplierName : AbstractTransformerCreationTask<Product>
{
public class Result
{
public string ProductName { get; set; }
public string SupplierName { get; set; }
}
public Products_ProductAndSupplierName()
{
TransformResults = products =>
from product in products
let category = LoadDocument<Supplier>(product.Supplier)
select new
{
ProductName = product.Name,
SupplierName = category.Name
};
}
}
elemarjr.com
@elemarjr
linkedin.com/in/elemarjr
elemarjr@ravendb.net
elemarjr@gmail.com
Mantenha contato!
Conhecendo RavenDB
Elemar Júnior
@elemarjr
elemarjr@ravendb.net
elemarjr@gmail.com
elemarjr.com

Weitere ähnliche Inhalte

Andere mochten auch

Desvendando a Plataforma de Serviços Windows Azure
Desvendando a Plataforma de Serviços Windows AzureDesvendando a Plataforma de Serviços Windows Azure
Desvendando a Plataforma de Serviços Windows Azure
LucasRomao
 

Andere mochten auch (20)

TDC2016POA | Trilha Python - Python Assíncrono: tudo ao mesmo tempo agora
TDC2016POA | Trilha Python - Python Assíncrono: tudo ao mesmo tempo agoraTDC2016POA | Trilha Python - Python Assíncrono: tudo ao mesmo tempo agora
TDC2016POA | Trilha Python - Python Assíncrono: tudo ao mesmo tempo agora
 
TDC2016POA | Trilha Pyhton - Python para Internet of Things
TDC2016POA | Trilha Pyhton -  Python para Internet of ThingsTDC2016POA | Trilha Pyhton -  Python para Internet of Things
TDC2016POA | Trilha Pyhton - Python para Internet of Things
 
TDC2016POA | Trilha Management - Ágil equilibrando o dia a dia de uma equipe
TDC2016POA | Trilha Management - Ágil equilibrando o dia a dia de uma equipeTDC2016POA | Trilha Management - Ágil equilibrando o dia a dia de uma equipe
TDC2016POA | Trilha Management - Ágil equilibrando o dia a dia de uma equipe
 
TDC2016POA | Trilha Management - Torne-se dispensável de suas funções.
TDC2016POA | Trilha Management - Torne-se dispensável de suas funções.TDC2016POA | Trilha Management - Torne-se dispensável de suas funções.
TDC2016POA | Trilha Management - Torne-se dispensável de suas funções.
 
TDC2016POA | Trilha Management - Lean Team Canvas para uma equipe de sucesso!
TDC2016POA | Trilha Management -  Lean Team Canvas para uma equipe de sucesso!TDC2016POA | Trilha Management -  Lean Team Canvas para uma equipe de sucesso!
TDC2016POA | Trilha Management - Lean Team Canvas para uma equipe de sucesso!
 
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam FilterTDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
TDC2016POA | Trilha Python - Heimdall Guard - Spam Filter
 
TDC2016POA | Trilha Management - Como criar melhores times de desenvolvimento
TDC2016POA | Trilha Management - Como criar melhores times de desenvolvimentoTDC2016POA | Trilha Management - Como criar melhores times de desenvolvimento
TDC2016POA | Trilha Management - Como criar melhores times de desenvolvimento
 
TDC2016POA | Trilha Banco de Dados - Conheça o Debezium: uma plataforma distr...
TDC2016POA | Trilha Banco de Dados - Conheça o Debezium: uma plataforma distr...TDC2016POA | Trilha Banco de Dados - Conheça o Debezium: uma plataforma distr...
TDC2016POA | Trilha Banco de Dados - Conheça o Debezium: uma plataforma distr...
 
Desvendando a Plataforma de Serviços Windows Azure
Desvendando a Plataforma de Serviços Windows AzureDesvendando a Plataforma de Serviços Windows Azure
Desvendando a Plataforma de Serviços Windows Azure
 
A plataforma Azure da Microsoft
A plataforma Azure da MicrosoftA plataforma Azure da Microsoft
A plataforma Azure da Microsoft
 
Introdução à computação na nuvem e Windows Azure
Introdução à computação na nuvem e Windows AzureIntrodução à computação na nuvem e Windows Azure
Introdução à computação na nuvem e Windows Azure
 
AAB308 - Cloud Computing Windows Azure - wcamb.pdf
AAB308 - Cloud Computing Windows Azure - wcamb.pdfAAB308 - Cloud Computing Windows Azure - wcamb.pdf
AAB308 - Cloud Computing Windows Azure - wcamb.pdf
 
Sistemas para o Mundo Real - TDC 2012
Sistemas para o Mundo Real - TDC 2012Sistemas para o Mundo Real - TDC 2012
Sistemas para o Mundo Real - TDC 2012
 
Desenvolvendo para o Windows Azure e SQL Azure
Desenvolvendo para o Windows Azure e SQL AzureDesenvolvendo para o Windows Azure e SQL Azure
Desenvolvendo para o Windows Azure e SQL Azure
 
O que há de novo no Microsoft Azure IaaS
O que há de novo no Microsoft Azure IaaSO que há de novo no Microsoft Azure IaaS
O que há de novo no Microsoft Azure IaaS
 
Mongo db no mundo real slides
Mongo db no mundo real   slidesMongo db no mundo real   slides
Mongo db no mundo real slides
 
Hadoop, Big Data e Cloud Computing
Hadoop, Big Data e Cloud ComputingHadoop, Big Data e Cloud Computing
Hadoop, Big Data e Cloud Computing
 
Azure @ Rio Cloud Meetup
Azure @ Rio Cloud MeetupAzure @ Rio Cloud Meetup
Azure @ Rio Cloud Meetup
 
TDC2016POA | Trilha Cloud Computing - Kubernetes para Desenvolvedores Docker
TDC2016POA | Trilha Cloud Computing - Kubernetes para Desenvolvedores DockerTDC2016POA | Trilha Cloud Computing - Kubernetes para Desenvolvedores Docker
TDC2016POA | Trilha Cloud Computing - Kubernetes para Desenvolvedores Docker
 
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
TDC2016POA | Trilha Cloud Computing - Microsoft Azure ? From Zero To Hero!
 

Ähnlich wie TDC2016POA | Trilha Banco de Dados - RavenDB: um banco de dados NoSQL de segunda geração

Calculation Package
Calculation PackageCalculation Package
Calculation Package
karlocamacho
 
Calculation Package
Calculation PackageCalculation Package
Calculation Package
karlocamacho
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
MongoDB
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
AASTHA76
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
armanuelraj
 

Ähnlich wie TDC2016POA | Trilha Banco de Dados - RavenDB: um banco de dados NoSQL de segunda geração (20)

Interactive analytics at scale with druid
Interactive analytics at scale with druidInteractive analytics at scale with druid
Interactive analytics at scale with druid
 
Performante Java Enterprise Applikationen trotz O/R-Mapping
Performante Java Enterprise Applikationen trotz O/R-MappingPerformante Java Enterprise Applikationen trotz O/R-Mapping
Performante Java Enterprise Applikationen trotz O/R-Mapping
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218
 
Calculation Package
Calculation PackageCalculation Package
Calculation Package
 
Calculation Package
Calculation PackageCalculation Package
Calculation Package
 
Migrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodbMigrating one of the most popular e commerce platforms to mongodb
Migrating one of the most popular e commerce platforms to mongodb
 
Migrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDBMigrating One of the Most Popular eCommerce Platforms to MongoDB
Migrating One of the Most Popular eCommerce Platforms to MongoDB
 
Connecting Teradata and MongoDB with QueryGrid
Connecting Teradata and MongoDB with QueryGridConnecting Teradata and MongoDB with QueryGrid
Connecting Teradata and MongoDB with QueryGrid
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Query for json databases
Query for json databasesQuery for json databases
Query for json databases
 
Webinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDBWebinar: Position and Trade Management with MongoDB
Webinar: Position and Trade Management with MongoDB
 
Mongo db ecommerce
Mongo db ecommerceMongo db ecommerce
Mongo db ecommerce
 
TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech Talk
 
Tsar tech talk
Tsar tech talkTsar tech talk
Tsar tech talk
 
CodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPigCodingSerbia2014-JavaVSPig
CodingSerbia2014-JavaVSPig
 
#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx#include customer.h#include heap.h#include iostream.docx
#include customer.h#include heap.h#include iostream.docx
 
Below is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdfBelow is my code- I have an error that I still have difficulty figurin.pdf
Below is my code- I have an error that I still have difficulty figurin.pdf
 
Using MongoDB As a Tick Database
Using MongoDB As a Tick DatabaseUsing MongoDB As a Tick Database
Using MongoDB As a Tick Database
 
Map reduce: beyond word count
Map reduce: beyond word countMap reduce: beyond word count
Map reduce: beyond word count
 
1
11
1
 

Mehr von tdc-globalcode

Mehr von tdc-globalcode (20)

TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidadeTDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
TDC2019 Intel Software Day - Visao Computacional e IA a servico da humanidade
 
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
TDC2019 Intel Software Day - Tecnicas de Programacao Paralela em Machine Lear...
 
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de SucessoTDC2019 Intel Software Day - ACATE - Cases de Sucesso
TDC2019 Intel Software Day - ACATE - Cases de Sucesso
 
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPATDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
TDC2019 Intel Software Day - Otimizacao grafica com o Intel GPA
 
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVinoTDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
TDC2019 Intel Software Day - Deteccao de objetos em tempo real com OpenVino
 
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
TDC2019 Intel Software Day - OpenCV: Inteligencia artificial e Visao Computac...
 
TDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devicesTDC2019 Intel Software Day - Inferencia de IA em edge devices
TDC2019 Intel Software Day - Inferencia de IA em edge devices
 
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca PublicaTrilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
Trilha BigData - Banco de Dados Orientado a Grafos na Seguranca Publica
 
Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#Trilha .Net - Programacao funcional usando f#
Trilha .Net - Programacao funcional usando f#
 
TDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case EasylocusTDC2018SP | Trilha Go - Case Easylocus
TDC2018SP | Trilha Go - Case Easylocus
 
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
TDC2018SP | Trilha Modern Web - Para onde caminha a Web?
 
TDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em GolangTDC2018SP | Trilha Go - Clean architecture em Golang
TDC2018SP | Trilha Go - Clean architecture em Golang
 
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QATDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
TDC2018SP | Trilha Go - "Go" tambem e linguagem de QA
 
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendenciaTDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
TDC2018SP | Trilha Mobile - Digital Wallets - Seguranca, inovacao e tendencia
 
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR ServiceTDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
TDC2018SP | Trilha .Net - Real Time apps com Azure SignalR Service
 
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NETTDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
TDC2018SP | Trilha .Net - Passado, Presente e Futuro do .NET
 
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
TDC2018SP | Trilha .Net - Novidades do C# 7 e 8
 
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
TDC2018SP | Trilha .Net - Obtendo metricas com TDD utilizando build automatiz...
 
TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#TDC2018SP | Trilha .Net - .NET funcional com F#
TDC2018SP | Trilha .Net - .NET funcional com F#
 
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net CoreTDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor  em .Net Core
TDC2018SP | Trilha .Net - Crie SPAs com Razor e C# usando Blazor em .Net Core
 

Kürzlich hochgeladen

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Kürzlich hochgeladen (20)

SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

TDC2016POA | Trilha Banco de Dados - RavenDB: um banco de dados NoSQL de segunda geração

  • 2. Olá, eu sou Elemar Jr
  • 3. ...
  • 5.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. { "Company": "companies/86", "Employee": "employees/4", "OrderedAt": "1996-11-07T00:00:00.0000000", "RequireAt": "1996-12-05T00:00:00.0000000", "ShippedAt": "1996-11-15T00:00:00.0000000", "ShipTo": { "Line1": "Adenauerallee 900", "Line2": null, "City": "Stuttgart", "Region": null, "PostalCode": "70563", "Country": "Germany" }, "ShipVia": "shippers/2", "Freight": 0.78, "Lines": [ { "Product": "products/1", "ProductName": "Chai", "PricePerUnit": 14.4, "Quantity": 15, "Discount": 0.15 }, { "Product": "products/23", "ProductName": "Tunnbröd", "PricePerUnit": 7.2, "Quantity": 25, "Discount": 0 } ] }
  • 15.
  • 16. using Raven.Client.Document; namespace Northwind { class Program { static void Main() { var documentStore = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "Northwind" }; documentStore.Initialize(); using (var session = documentStore.OpenSession()) { var p = session.Load<dynamic>("products/1"); System.Console.WriteLine(p.Name); } } } }
  • 17. public class Product { public string Name { get; set; } public string Supplier { get; set; } public string Category { get; set; } public string QuantityPerUnit { get; set; } public float PricePerUnit { get; set; } public int UnitsInStock { get; set; } public int UnitsOnOrder { get; set; } public bool Discontinued { get; set; } public int ReorderLevel { get; set; } }
  • 18. using Raven.Client.Document; namespace Northwind { class Program { static void Main() { var documentStore = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "Northwind" }; documentStore.Initialize(); using (var session = documentStore.OpenSession()) { var p = session.Load<Product>("products/1"); System.Console.WriteLine(p.Name); } } } }
  • 19. public static class DocumentStoreHolder { private static readonly Lazy<IDocumentStore> LazyStore = new Lazy<IDocumentStore>(() => { var store = new DocumentStore { Url = "http://localhost:8080", DefaultDatabase = "Northwind" }; return store.Initialize(); }); public static IDocumentStore Store => LazyStore.Value; }
  • 20. string categoryId; using (var session = DocumentStoreHolder.Store.OpenSession()) { var newCategory = new Category { Name = "My New Category", Description = "Description of the new category" }; session.Store(newCategory); categoryId = newCategory.Id; session.SaveChanges(); }
  • 21. using (var session = DocumentStoreHolder.Store.OpenSession()) { var storedCategory = session .Load<Category>(categoryId); storedCategory.Name = "abcd"; session.SaveChanges(); }
  • 22. using (var session = DocumentStoreHolder.Store.OpenSession()) { session.Delete(categoryId); session.SaveChanges(); }
  • 23. Product[] products = session.Load<Product>(new[] { "products/1", "products/2", "products/3" });
  • 24. var p = session .Include<Product>(x => x.Category) .Load(1); var c = session.Load<Category>(p.Category);
  • 25. var order = session .Include<Order>(o => o.Company) .Include(o => o.Employee) .Include(o => o.Lines.Select(l => l.Product)) .Load("orders/1");
  • 26. { "Company": "companies/86", "Employee": "employees/4", "OrderedAt": "1996-11-07T00:00:00.0000000", "RequireAt": "1996-12-05T00:00:00.0000000", "ShippedAt": "1996-11-15T00:00:00.0000000", "ShipTo": { "Line1": "Adenauerallee 900", "Line2": null, "City": "Stuttgart", "Region": null, "PostalCode": "70563", "Country": "Germany" }, "ShipVia": "shippers/2", "Freight": 0.78, "Lines": [ { "Product": "products/1", "ProductName": "Chai", "PricePerUnit": 14.4, "Quantity": 15, "Discount": 0.15 }, { "Product": "products/23", "ProductName": "Tunnbröd", "PricePerUnit": 7.2, "Quantity": 25, "Discount": 0 } ] } var order = session .Include<Order>(o => o.Company) .Include(o => o.Employee) .Include(o => o.Lines.Select(l => l.Product)) .Load("orders/1");
  • 27. private static void QueryCompanyOrders(int companyId) { using (var session = DocumentStoreHolder.Store.OpenSession()) { var orders = ( from order in session.Query<Order>() .Include(o => o.Company) where order.Company == $"companies/{companyId}" select order ).ToList(); var company = session.Load<Company>(companyId); if (company == null) { WriteLine("Company not found."); return; } WriteLine($"Orders for {company.Name}"); foreach (var order in orders) { WriteLine($" {order.Id} - {order.OrderedAt}"); } } }
  • 28. var orders = ( from order in session.Query<Order>() where order.Company == "companies/1" orderby order.OrderedAt select order ).ToList();
  • 29. var results = new List<Order>(); foreach (var o in GetDocumentsFor("Orders")) { if (o.Company == "companies/1") results.Add(o); } var orderedResults = results.Sort((a, b) => a.OrderedAt.CompareTo(b.OrderedAt));
  • 30.
  • 31. public class Employees_ByFirstAndLastName : AbstractIndexCreationTask<Employee> { public Employees_ByFirstAndLastName() { Map = (employees) => from employee in employees select new { FirstName = employee.FirstName, LastName = employee.LastName }; } }
  • 32. public class People_Search : AbstractMultiMapIndexCreationTask<People_Search.Result> { public class Result { public string SourceId { get; set; } public string Name { get; set; } public string Type { get; set; } } public People_Search() { AddMap<Company>(companies => from company in companies select new Result { SourceId = company.Id, Name = company.Contact.Name, Type = "Company's contact" } ); ...
  • 33. AddMap<Supplier>(suppliers => from supplier in suppliers select new Result { SourceId = supplier.Id, Name = supplier.Contact.Name, Type = "Supplier's contact" } ); AddMap<Employee>(employees => from employee in employees select new Result { SourceId = employee.Id, Name = $"{employee.FirstName} {employee.LastName}", Type = "Employee" } ); ...
  • 34. Index(entry => entry.Name, FieldIndexing.Analyzed); Store(entry => entry.SourceId, FieldStorage.Yes); Store(entry => entry.Name, FieldStorage.Yes); Store(entry => entry.Type, FieldStorage.Yes); } }
  • 35. public static IEnumerable<People_Search.Result> Search( IDocumentSession session, string searchTerms ) { var results = session.Query<People_Search.Result, People_Search>() .Search(r => r.Name, searchTerms, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards) .ProjectFromIndexFieldsInto<People_Search.Result>() .ToList(); return results; }
  • 36. static void Main(string[] args) { Console.Title = "Multi-map sample"; using (var session = DocumentStoreHolder.Store.OpenSession()) { while (true) { Console.Write("nSearch terms: "); var searchTerms = Console.ReadLine(); foreach (var result in Search(session, searchTerms)) { Console.WriteLine($"{result.SourceId}t{result.Type}t{result.Name}"); } } } }
  • 37.
  • 38. public class Products_ByCategory : AbstractIndexCreationTask<Product, Products_ByCategory.Result> { public class Result { public string Category { get; set; } public int Count { get; set; } } public Products_ByCategory() { Map = products => from product in products select new { Category = product.Category, Count = 1 }; Reduce = results => from result in results group result by result.Category into g select new { Category = g.Key, Count = g.Sum(x => x.Count) }; } }
  • 39. public class Employees_SalesPerMonth : AbstractIndexCreationTask<Order, Employees_SalesPerMonth.Result> { public class Result { public string Employee { get; set; } public string Month { get; set; } public int TotalSales { get; set; } } public Employees_SalesPerMonth() { } }
  • 40. Map = orders => from order in orders select new { order.Employee, Month = order.OrderedAt.ToString("yyyy-MM"), TotalSales = 1 };
  • 41. Reduce = results => from result in results group result by new { result.Employee, result.Month } into g select new { g.Key.Employee, g.Key.Month, TotalSales = g.Sum(x => x.TotalSales) };
  • 42. using (var session = DocumentStoreHolder.Store.OpenSession()) { var query = session .Query<Employees_SalesPerMonth.Result, Employees_SalesPerMonth>() .Include(x => x.Employee); var results = ( from result in query where result.Month == "1998-03" orderby result.TotalSales descending select result ).ToList(); foreach (var result in results) { var employee = session.Load<Employee>(result.Employee); Console.WriteLine($"{employee.FirstName} {employee.LastName} made {result.TotalSales} sales."); } }
  • 43. public class Products_ByCategory : AbstractIndexCreationTask<Product, Products_ByCategory.Result> { public class Result { public string Category { get; set; } public int Count { get; set; } } public Products_ByCategory() { Map = products => from product in products let categoryName = LoadDocument<Category>(product.Category).Name select new { Category = categoryName, Count = 1 }; Reduce = results => from result in results group result by result.Category into g select new { Category = g.Key, Count = g.Sum(x => x.Count) }; } }
  • 44. public class Products_ProductAndSupplierName : AbstractTransformerCreationTask<Product> { public class Result { public string ProductName { get; set; } public string SupplierName { get; set; } } public Products_ProductAndSupplierName() { TransformResults = products => from product in products let category = LoadDocument<Supplier>(product.Supplier) select new { ProductName = product.Name, SupplierName = category.Name }; } }