ravendb

RavenDB - retrieving part of document

我的未来我决定 提交于 2019-11-30 17:28:19
I am playing with Raven DB for few days and I would like to use it as a storage for my Web chat application. I have document which contains some user data and chat history - which is big collection chat messages. Each time I load user document chat history is also loaded, even if I need only few fields like: user name, password and email. My question is: how to load only part of document from database ? Tomek, You can't load a partial document, but you can load a projection. session.Query<User>() .Where(x=>x.Name == name) .Select( x=> new { x.Name, x.Email }); That will load only the

RavenDB changes metadata “Raven-Entity-Name”

萝らか妹 提交于 2019-11-30 17:17:11
问题 I noticed that when I add a document to RavenDB and see the "Raven-Entity-Name" metadata it makes it plural. E.g. if my model name was Product it changes it to Products . Why such kind for behavior? If I have create an index I am forced to use docs.Products 回答1: It's part of the philosophy of RavenDB to do convention over configuration, so it does this by default. But you can override it if you want to, you can do something like this: _documentStore = new DocumentStore { Url = "http:/

Querying a child collection by multiple values in RavenDB

眉间皱痕 提交于 2019-11-30 14:33:46
I'm using RavenDB build 371 and I have the following model: class Product { public string Id { get; set; } public ProductSpec[] Specs { get; set; } } class ProductSpec { public string Name { get; set; } public string Value { get; set; } } I would like to be able to query for products which have a set of specs. When querying by a single spec: session.Query<Product>() .Where(product => product.Specs.Any(spec => spec.Name == "Color" && spec.Value == "Red")) .ToList(); The expected results are returned, however when an additional spec predicate is added: session.Query<Product>() .Where(product =>

Handling namespace changes with TypeNameHandling.All

女生的网名这么多〃 提交于 2019-11-30 13:58:20
问题 I managed to get my self into a fix with the JSON.net TypeNameHandling. I am storing a JSON formatted object using RavenDB and set the TypeNameHandling of the JSON.net serializer to true in order to deal with an inheritance structure I have in place. I needed to change the namespace of the document which I am storing, so now when it is deserialzed it is throws the error "Error resolving type specified in JSON" because the reference to the type in the JSON document no longer exists. Is it

Specifying Collection Name in RavenDB

本小妞迷上赌 提交于 2019-11-30 11:23:06
问题 So lets say I have 3 objects Fruit, Apple and Orange. Fruit is the abstract base class for Apple and Orange. When I use session.Store(myApple), it puts it into the Apples collection. myOrange stores in the Oranges collection. Makes sense. Can I tell Raven that I want a Fruits collection that could hold Apples or Oranges? Mongodb allows this since it lets me explicitly specify the collection name. The RavenDB collections documentation says: The expected usage pattern is that collections are

ASP.NET MVC 3, RavenDB, & Autofac Issue Plus 2 Other Autofac Questions

旧城冷巷雨未停 提交于 2019-11-30 04:11:02
问题 NOTE: There are 3 questions in here and I did not make separate questions since they are all somewhat related to the same code. I have the following code that registers the connection to my RavenDB in the Application_Start once per the application's life cycle: var store = new DocumentStore { Url = "http://localhost:8080" }; store.Initialize(); builder.RegisterInstance(store).SingleInstance(); Now this works fine and this is something that should be created only once per the application's

RavenDB: How to query with multiple search terms

◇◆丶佛笑我妖孽 提交于 2019-11-30 02:53:37
My entity is: class Resource { string Name; string EmployeeId; } How do I query for resources of multiple employees? I tried this: Resource[] FindResourcesByEmployees(string[] employeeIds) { return this.Session.Query<Resource>() .Where(r => employeeIds.Contains(r.EmployeeId)) .ToArray(); } However that gives me NotSupportedException: Method not supported: Contains. Then I tried the following method: Resource[] FindResourcesByEmployees(string[] employeeIds) { return this.Session.Query<Resource>() .Where(r => employeeIds.Any(v => v == r.EmployeeId)) .ToArray(); } That throws

RavenDB Map-Reduce Example using .NET Client

╄→гoц情女王★ 提交于 2019-11-29 20:38:19
I'm looking for an example of how to implement and use Map-Reduce within the RavenDB .NET Client. I'd like to apply it to a specific scenario: generating unique and total visitor counts. A sample document that would be stored within RavenDB: public class StatisticsEntry { public string Id { get; set; } public string UserId { get; set; } } I can figure out how to create a standard index using Map, but I'm lost as to how to actually use the Reduce function, and then retrieve the results. Unfortunately, the example provided on the RavenDB Site doesn't explain what's going on so that I can

Problems with RavenDB.Client reference in asp.net 5.0 project.json

♀尐吖头ヾ 提交于 2019-11-29 14:58:17
I'm trying to build a RavenApiController with the new ASP.NET 5.0 (aka Asp.Net vNext) stuff and can't seem to get the RavenDB.Client references to work at all. The error I get is Error CS0246 The type or namespace name 'Raven' could not be found (are you missing a using directive or an assembly reference?) SharedIO.ASP.NET Core 5.0 RavenApiController.cs 3 My project.json is as follows { "webroot": "wwwroot", "version": "1.0.0-*", "exclude": [ "wwwroot" ], "packExclude": [ "**.kproj", "**.user", "**.vspscc" ], "dependencies": { "Microsoft.AspNet.Server.IIS": "1.0.0-beta2", "Microsoft.AspNet

How to disable RavenDB replication

一个人想着一个人 提交于 2019-11-29 10:17:54
How do I disable RavenDB replication? The reason for that is I have a simple database on one server and I don't need any replication at this point. IDocumentStore tmpStore = new DocumentStore { Url = url }; tmpStore.Initialize(); tmpStore.DatabaseCommands.EnsureDatabaseExists(dbName); // WebException If I try to ensure that database was created I get a WebException with HTTP status 404. This error occurred when RavenDB makes request to /docs/Raven/Replication/Destinations . Or shall I just ignore this exception? The web exception is thrown and caught internally inside RavenDB Client. You can