ASP.NET CORE 의 Cosmos db api (asp.net core cosmos db connection)

ASP.NET CORE 의 Cosmos db api (asp.net core cosmos db connection)

Core Cosmos db API

GITHUB 코드:

// program class 안에 초기 configuration

private const string EndpointUri = " http://localhost:8001 ";

private const string PrimaryKey = ""

private DocumentClient client

# client 객체 생성

this.client = new DocumentClient(new Uri(EndpointUri, PrimaryKey)

# Database create

await this.client.CreateDatabaseIfNotExistsAsync( new Database { Id = "FamilyDB"} );

# Database delete

await this.DeleteDatabaseAsync(UriFacotory.CreateDatabaseUri(""));

# Collection create

await this.client.CreateDocumentCollectionIfNotExistsAync(UriFactory.CreateDatabaseuri("FamilyDB"), new DocumentCollection { Id = "FamilyCollection" })

# creata document in Collection

await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), family);

# read document

# update document

await this.client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, familyName, updatedFamily);

# delete document

await this.client.DeleteDocumentAsync(UrtiFactory.CreateDocumentUri(databaseName, collectionName, docmentName));

# Linq query

FeedOptions

FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1, EnableCrossPartitionQuery = true };

IQueryabke familyQuery = this.client.CreateDocumentQuery( UriFactory.CreateDocumentCollectionUri(databasName, collectionName), queryOptions).Where(f => f.LastName == ":)

foreach (Family family in familyQuery)

{

Console.WrtieLine(family)

}

IQueryable familyQueryInSql = this.client.CreateDocumentQuery( UriFactory.CreateDocumentCollectionUri(databaseName, CollectionName), "SELECT * FROM family WHERE Family.LastName='Andresen", queryOptions);

참고자료:

MSDN 자료

from http://blog.doosikbae.com/110 by ccl(A) rewrite - 2020-03-06 04:20:59

댓글

이 블로그의 인기 게시물

🐱‍💻Installing IIS Components Windows 10

2017년 1월 스타트업에서 구인할때 주로 원하는 개발 기술

Creating Cascading DropDownLists in ASP.Net (연속적인 셀렉트박스...