Google Firestore-使用C#从SQL Server导入数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Google Firestore-使用C#从SQL Server导入数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2578字,纯文字阅读大概需要4分钟。
内容图文
![Google Firestore-使用C#从SQL Server导入数据](/upload/InfoBanner/zyjiaocheng/883/f1fb131e910744589d41b75a5319b4d0.jpg)
我需要将数据从保存在sql服务器数据库上的事务迁移到Firestore数据库.我需要从一个连续的过程中以编程方式执行此操作,该过程将反映Firestore上所有新事务中的相同数据.
目前,我找不到任何要使用C#在Firestore上写入数据的SDK.
有什么想法吗 ?
解决方法:
您可以获取一个新生的C#SDK.在这里查看Jon Skeet的回购:http://jskeet.github.io/google-cloud-dotnet/docs/Google.Cloud.Firestore.Data/
(以下来自GitHub)
安装
从NuGet安装Google.Cloud.Firestore.Data软件包.以常规方式将其添加到您的项目中(例如,通过在Visual Studio中右键单击该项目并选择“ Manage NuGet Packages …”).请确保您启用了预发行包(例如,在Visual Studio NuGet用户界面中,选中“包含预发行”框).
认证方式
在Google Cloud Platform上运行时,无需采取任何措施即可进行身份验证.
否则,验证API调用的最简单方法是下载服务帐户JSON文件,然后将GOOGLE_APPLICATION_CREDENTIALS环境变量设置为引用它.凭据将自动用于身份验证.有关更多详细信息,请参见Getting Started With Authentication guide.
入门
一切都从FirestoreDb开始.使用Create或CreateAsync方法创建一个实例,并传入您的Google Cloud项目ID.默认凭据将用于与服务器进行身份验证.
从那里,您可以创建,获取和修改文档以及运行查询.
样例代码
FirestoreDb db = FirestoreDb.Create(projectId);
// Create a document with a random ID in the "users" collection.
CollectionReference collection = db.Collection("users");
DocumentReference document = await collection.AddAsync(new { Name = new { First = "Ada", Last = "Lovelace" }, Born = 1815 });
// A DocumentReference doesn't contain the data - it's just a path.
// Let's fetch the current document.
DocumentSnapshot snapshot = await document.SnapshotAsync();
// We can access individual fields by dot-separated path
Console.WriteLine(snapshot.GetField<string>("Name.First"));
Console.WriteLine(snapshot.GetField<string>("Name.Last"));
Console.WriteLine(snapshot.GetField<int>("Born"));
// Or deserialize the whole document into a dictionary
Dictionary<string, object> data = snapshot.ToDictionary();
Dictionary<string, object> name = (Dictionary<string, object>) data["Name"];
Console.WriteLine(name["First"]);
Console.WriteLine(name["Last"]);
// See the "data model" guide for more options for data handling.
// Query the collection for all documents where doc.Born < 1900.
Query query = collection.Where("Born", QueryOperator.LessThan, 1900);
QuerySnapshot querySnapshot = await query.SnapshotAsync();
foreach (DocumentSnapshot queryResult in querySnapshot.Documents)
{
string firstName = queryResult.GetField<string>("Name.First");
string lastName = queryResult.GetField<string>("Name.Last");
int born = queryResult.GetField<int>("Born");
Console.WriteLine($"{firstName} {lastName}; born {born}");
}
内容总结
以上是互联网集市为您收集整理的Google Firestore-使用C#从SQL Server导入数据全部内容,希望文章能够帮你解决Google Firestore-使用C#从SQL Server导入数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。