确保文档中的唯一电子邮件地址 [英] Ensuring Unique Email Address in Documents

查看:50
本文介绍了确保文档中的唯一电子邮件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建或更新具有 EmailAddress 属性的 UserAccount 实体,同时确保 EmailAddress 是唯一的.UserAccount 有它自己的 Id 类型的 long 属性,这样我就可以跟踪每个 UserAccount 实体,如如果用户希望更改其电子邮件地址,则使用电子邮件地址作为文档 ID 会出现问题.

I want to create or update a UserAccount entity with an EmailAddress property, whilst ensuring the EmailAddress is unique. UserAccount has it's own Id property of type long, this is just so I can track each UserAccount entity, as using the email address as the document id would present issues if the user wishes to change their email address.

我听说我可以创建一个名为 UniqueEmailAddresses 的新集合,它可以是空(或接近空?)文档的集合,而电子邮件地址将是实际的文档 ID.

I've heard I could create a new collection called UniqueEmailAddresses that could be collection of empty (or near empty?) documents and the email address would be the actual document id.

这是正确的吗?如果我在一次交易中更新两个集合,这是确保具有相同电子邮件地址的 2 个文档不会出现在 UserAccount 集合中的最佳方法吗?以用户的电子邮件地址作为 id 添加这个额外的集合,在处理数百万用户时会导致任何性能问题吗?是否可以创建一个空文档?我走对了路吗?

Is this correct? If I update both collections in one transaction, is this the best way to ensure that 2 documents with the same email addresses don't end up in UserAccount collection? Does adding this extra collection with the user's email address as the id, cause any performance issues when dealing with millions of users? Is it possible to create an empty document? Am I going down the right path?

这些是可用的包,我需要添加哪个包才能获得独特的约束功能?

These are the available bundles, which bundle do I need to add to get the unique constraint features?

我已将 Raven.Bundles.UniqueConstraints DLL 添加到文件夹 ~/App_Data/RavenDB/Plugins(我使用的是嵌入式服务器)并将我的文档存储提供程序更改为:

I've added the Raven.Bundles.UniqueConstraints DLL to the folder ~/App_Data/RavenDB/Plugins (I'm using the embedded server) and changed my Document Store Provider to:

protected override IDocumentStore CreateInstance(IContext context)
{
    EmbeddableDocumentStore documentStore = new EmbeddableDocumentStore()
    {
        DataDirectory = @"~\App_Data\RavenDB",
        UseEmbeddedHttpServer = true,
        Configuration = { Port = 8181, PluginsDirectory = @"~\App_Data\RavenDB\Plugins" }
    };

    documentStore.RegisterListener(new UniqueConstraintsStoreListener());

    documentStore.Initialize();

    return documentStore;
}

但它仍然没有显示在可用包列表中,当我通过打破约束进行测试时,我对 checkResult.ConstraintsAreFree() 的调用错误地返回了 true.

But it still doesn't show in the available bundles list and my call to checkResult.ConstraintsAreFree() wrongly returns true when I'm testing by breaking the constraint.

推荐答案

RavenDB 有独特的约束包的概念,可以为您完成所有这一切.

RavenDB has the notion of the unique constraints bundles that does all of it for you.

查看文档:http://ravendb.net/docs/article-page/3.0/csharp/client-api/bundles/how-to-work-with-unique-constraints-bundle

这篇关于确保文档中的唯一电子邮件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆