How can I effectively check for a document in RavenDB

I have an entity of the Contacts domain, the contact is linked to lists via the MemberOf property (contains the list identifier in RavenDB)

public class Contact
{
    public string Id { get; set; }
    public string Email { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }
    public List<string> MemberOf { get; set; }
}

I want to use RavenDB to store contacts, one way to download contacts is through CSV files (in bulk). I thought how I can prevent data duplication when two CSV files have the same contacts, I believe that the contacts are the same when they have the same email address - this is due to my domain logic. A contact can be a member of two different CSV lists, for example.
I upload two CSV lists that have the same email address field, the problem is that I want the contacts class to be established that MemeberOf has two lists, so that I do not have duplicate entries for each list, because the domain The logic of my application requires one contact object for each email for statistical analysis.

, , .

+3
1

, RavenDB , - id . , , , - . :

using (var session = docStore.OpenSession())
{
    foreach (var csvItemToImport in csvfile)
    {
        var existingDoc = session.Load<Contact>(csvItemToImport.Email);    
        if (existingDoc == null)
        {
            //No doc with the given email exists, add a new one
            session.Store(new Contact{ ... });
        }
        else
        {
            existingDoc.MemberOf.Add(csvItemToImport.ListName)
            // No need to store the doc, it tracked in the session automatically
        }     
    }
    //Save the changes so far back to the dBase, in a single batched transaction
    session.SaveChanges();
}

doc URL- (/docs/contacts/blah@blah.co.uk), "@" .

POCO :

public class Contact
{
    public string Id { get; set; } //this is actually an email address 
    public string Name { get; set; }
    public string Country { get; set; }
    public List<string> MemberOf { get; set; }
}

, , ( - ). . 2 , Contact doc , .

+4

All Articles