![]() |
VOOZH | about |
This article illustrates using LINQ to access tables within the Cosmos DB via the CData ADO.NET Data Provider for Cosmos DB. To achieve this, we will use LINQ to Entity Framework, which facilitates the generation of connections and can be seamlessly employed with any CData ADO.NET Data Providers to access data through LINQ.
See the help documentation for a guide to setting up an EF 6 project to use the provider.
Enter your data source connection information.
To obtain the connection string needed to connect to a Cosmos DB account using the SQL API, log in to the Azure Portal, select Azure Cosmos DB, and select your account. In the Settings section, click Connection String and set the following values:
Below is a typical connection string:
AccountEndpoint=myAccountEndpoint;AccountKey=myAccountKey;
Using the entity you created, you can now perform select , update, delete, and insert commands. For example:
CosmosDBEntities context = new CosmosDBEntities();
var customersQuery = from customers in context.Customers
select customers;
foreach (var result in customersQuery) {
Console.WriteLine("{0} {1} ", result.id, result.City);
}
See "LINQ and Entity Framework" chapter in the help documentation for example queries of the supported LINQ.
Download a free trial of the Cosmos DB Data Provider to get started:
Download NowLearn more:
👁 Cosmos DB IconRapidly create and deploy powerful .NET applications that integrate with Cosmos DB document databases.