w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Store new document to specific collection in RavenDB via REST
While metadata is returned in the @metadata section, that's not how you send it in. That's because you don't have control over every metadata value. For example, passing in an etag wouldn't make sense. Instead, for the metadata values you can control, send them in the HTTP headers. $headers = @{"Raven-Entity-Name"="Entries"} Invoke-RestMethod -Headers $headers ...

Categories : Powershell

FormCollection to expandoObject
Well, not the most elegant code (probably better ways to do it), but one way could be something like this: [HttpPost] public ActionResult Test(FormCollection collection) { dynamic expando = new ExpandoObject(); var dictionary = (IDictionary<string, object>) expando; foreach (var item in collection.AllKeys.ToDictionary(key => key, value => collection[value])) { dictionary.Add(item.Key, item.Value); } // your expando will be populated here ... // do awesomeness } I hope this helps (at least it might give you an idea).

Categories : C#

Is it possible to query list of ExpandoObject?
Your suggestion is right, you would be able to query a collection of dynamic objects using the dot notation. var ids = generatedItems.Cast<dynamic>().Select(x => x.Id); However, keep in mind that there's no type safety here and, as you stated, IntelliSense is of no use, since you're using dynamic objects. If your code depends on whether one of those objects have an optional property (e.g., some have "Title", others don't), then it will require a little more manual labor. if((generatedItems as IDictionary<String, object>).ContainsKey("Title")) { }

Categories : C#

How to store data with abstract type? Is it sane to store data as sql_variant data type?
It's hard to determine right answer from your question. What data types you are expecting to be and what are you going to do with that types? Because,if you are going to create to many tables for each type you will end up in complexity and more size on disk than using sql_variant type. Keep in mind that when using sql_variant to represent boolean, will only represent 1 byte of overhead(for storing data type kind) + variable length bytes(wich you probably already have in table). But if you are using that type fore some complex mission critical logic and if yours data access framework doesn't support sql_variant you should not use sql_variant.

Categories : SQL

Sqlite database unable to delete objects, failing with message "Cannot store type: "
Rather than use: public int DeleteItem<T>(int id) where T : IBusinessEntity, new() { lock (locker) { #if NETFX_CORE return Delete(new T() { ID = id }); #else return Delete<T> (new T () { ID = id }); #endif } } Use this instead: public int Delete(object objectToDelete) { var map = GetMapping(objectToDelete.GetType()); var pk = map.PK; if (pk == null) { throw new NotSupportedException("Cannot delete " + map.TableName + ": it has no PK"); } var q = string.Format("delete from "{0}" where "{1}" = ?", map.TableName, pk.Name); return Execute(q, pk.GetValue(objectToDelete)); }

Categories : Sqlite

Variable store function as primitive type or reference type?
The value of f2 is, like f1, a reference to the same function. You can use the fact that functions are objects to prove it : var f1 = function(){} var f2 = f1; f1.a = 3; console.log(f2.a); // logs 3 But as you can't change a function core, there is little practical use in knowing this, apart the fact you don't use much memory if you duplicate a function reference.

Categories : Javascript

"'System.Dynamic.ExpandoObject' does not contain a definition for "PropertyName"
I gather this is expected behavior when using an ExpandoObject. I took a look at the IntelliTrace log for this code and the entries for the exceptions you are seeing are paired up: Exception:Thrown: "'System.Dynamic.ExpandoObject' does not contain a definition for 'clients'" (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) Exception:Caught: "'System.Dynamic.ExpandoObject' does not contain a definition for 'clients'" (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) i.e. The exception is being thrown and then caught. If you look at the Call Stack Window you will see that the throws and catches are within the .NET Framework. BTW, I did have to make a small change to your code to make it run: I changed: root.clients.client.Count to root.clients.Count in the for loop.

Categories : C#

How to use a lambda expression on an ExpandoObject C# to find an array element value?
I assume gifts is of the type List<Gift[]>. Then you would do: var test = ((List<Gift[]>)Model.moduleData.gifts).FirstOrDefault(item => item[index][0] == 99); The reason is that the type of gifts is not known at compile time, so the C# compiler has no way of resolving the type of lambda that's being specified.

Categories : C#

How to get ServiceStack to serialize a dynamic (ExpandoObject) property on request
You may have seen this announcement: The next major v4.0 will also be a "breaking-release", with new features protected under an "AGPL/FOSS License Exception" and include a number of breaking changes that have built up over time, including upgrading all projects (to .NET 4+), major code and NuGet package re-factoring, clean-up and removal of deprecated code, better consistency / simplification of some concepts and implementation of some roadmap features I've been wanting to add but never had time for. Fixes and releases will continue to v3.x and be maintained in a separate v3 branch until v4.0 comes out of beta. As there's no reason to fix dynamic object support in the current 3.x branch, which doesn't support .Net4.0, the answer is 'No, ServiceStack can't serialize the JSON request

Categories : Json

RavenDB OrderBy
If you are using an index you need to set the sortoptions for the Order property. From http://ravendb.net/docs/client-api/querying/static-indexes/customizing-results-order Numerical values, on the other hand, are stored as text and therefore require the user to specify explicitly what is the number type used so a correct sorting mechanism is enforced. This is quite easily done, by declaring the required sorting setup in SortOptions in the index definition: Sort(x => x.Order, SortOptions.Int); The index outlined above will allow sorting by value on the user's age (1, 2, 3, 11, etc). If we wouldn't specify this option, it would have been sorted lexically (1, 11, 2, 3, etc). The default SortOptions value is String. Appropriate values available for all numeric types (Byte, Doub

Categories : C#

RavenDB indices chains
Yes. You can now do this. Enable the Scripted Index Results bundle Write your first index, for example - a map/reduce index. Write a script that writes the result back to another document. Write a new index against those documents. As changes to the original documents are indexed, the resulting changes get written to new documents, which then get indexed. Repeat if desired, just be careful not to create an endless loop. This is a new feature for RavenDB 2.5. Oren describes it in this video at 21:36.

Categories : C#

Nservicebus 4 with azure and RavenDB
You have 2 options: Use RavenHQ and assign the connection string, see http://support.nservicebus.com/customer/portal/articles/859362-using-ravendb-in-nservicebus-%E2%80%93-connecting Use SqlServer as persistence

Categories : Azure

Bulk insert in RavenDB
You should probably not be upserting one record at a time. RavenDB has a bulk insert feature that will make things much easier and faster. See http://ravendb.net/docs/2.0/client-api/advanced/bulk-inserts

Categories : C#

RavenDB polymorphic Index
What are you trying to do? If the end result is to query all Principals, then load the entire User or AppInstance, why not just go straight for querying all Users or all AppInstances? Raven won't store base classes; it will only store the most derived type (User or AppInstance, in your case). So you'll have a collection of Users and a collection of AppInstances. If you really need to query both at once, you can use Multi Map indexes. You can also change the entity name and store both in a single Principal collection. But it's difficult to recommend a solution without knowing what you're trying to do. Explain what you're trying to do and we'll tell you the proper way to get there.

Categories : C#

OrderBy on a Sub Collection using RavenDB
result.OrderBy(x => x.Field.Name) will return a collection as LINQ will not change the collection on which it is called rather it returns a new collection which has the required result. So do result = result.OrderBy(x => x.Field.Name);

Categories : C#

Error in selecting value from RavenDB
If you try to instanciate var ctrl = new Activation(); and do ctrl.validate(x); it won't work as OnActionExecuting didn't run. That function is called automatically by the MVC framework when serving a request, not when manually testing. Since MVC instantiates a new controller on each requests anyway, you should move the RavenSession initialization to the constructor since you do not seem to use any info in the request context: public class RavenBaseController : Controller { public IDocumentSession RavenSession { get; protected set; } public RavenBaseController() { RavenSession = MvcApplication.Store.OpenSession("ravendbtesting"); } protected override void OnActionExecuted(ActionExecutedContext filterContext) { if (filterContext.IsChildAction) retu

Categories : C#

RavenDB domain error
Connecting locally, are you using http://localhost:[port]? I've had problems using the domain name locally. Try running your application locally and connect to the RavenDB via locahost address.

Categories : Windows

Ravendb Array intersect
The Array intersection is not allowed, but you can write your query as follows: var colors = session.Query<Color>() .Where(c => c.colorArray.Any(x => x == "r") && c.colorArray.Any(x => x == "e") && c.colorArray.Any(x => x == "d")); Please note that in order for this to work, you need to use strings, not chars. The colorArray property in your Color class needs to be defined as: public string[] colorArray { get; set; } The reason is that if you use char[], then the query will check for the numeric values (ASCII codes) rather then the string values (ex: 'r' will be interpreted by the query engine as 114, 'e' to 101 and 'd' to 100). Now, to take this

Categories : Arrays

Load all documents from RavenDB
I figured it out: I have to wait for non staled results. So if I change my Query out with this: session.Query<Model.Category>().Customize(cr => cr.WaitForNonStaleResults()).ToList(); it works just fine.

Categories : C#

Data type to store value <=10^20 in C/C++
A float and a double can store values in the range you have specified, and beyond. Note that it cannot store the precise discrete integers in that range, merely an approximation that is often relevant to the order of magnitude.

Categories : C++

RavenDB get ID of newly stored document
The Id property of the Product class must be of type string instead of integer. Then you will be able to retrieve the autogenerated id after the operation: Product p = new Product() { Title = "My Fancy Product" }; RavenSession.Store(p); string id = p.Id; More information can be found in the documentation (Document IDs section): In the example above we had a string Id property for BlogPost, and left it blank. It is this property that will be used as the "primary key" for this document. Note how RavenDB generated an ID for us, "BlogPosts/1", based on the default convention which we will discuss in a second. If there is no Id property on a document, RavenDB will still generate a unique ID, but it will be retrievable only by calling session.Advanced.GetDocumentId(objec

Categories : C#

RavenDB DocumentStore in Class Library
You will have to reference RavenDB from the class library, you can't really go around that. You may find the following article insightful, though: http://novuscraft.com/blog/ravendb-and-the-repository-pattern

Categories : C#

RavenDB Query does not return all records
By default, queries return up to 128 records. Use an explicit Take(n) to get more records.

Categories : C#

RavenDB - wait for document creation
Well, I'm not sure what mechanism you are using for event processing, but I have been in a similar situation with something like NServiceBus. I don't think this exactly a RavenDB problem. You would probably have the same issue if you were writing to a SQL Server database. The generalized problem is, Create and Update events are fired off, but they are received and processed in the wrong order. What to do? Well the general advice is that your event handlers should be idempotent, and should retry when failed. So if Update is received first, it will throw an exception and be scheduled for retry. Then Create comes through, then Update retries and all is good. Specifically blocking and waiting in the handler for the Update event is not advised, because if you had several of these then t

Categories : C#

Where should I place business logic when using RavenDB
There's two main parts to consider here. Firstly, as you have already noted, if you go by the word of the more fanatical RavenDB fans it is some mythical beast which is exempt from the otherwise commonly accepted laws of good application design and should be allowed to permeate throughout your application at will. It depends on the situation of course but to put it simply, if you would structure your application a certain way with something like SQL Server, do the same with RavenDB. If you would have a DAL layer, ORM, repository pattern or whatever with a SQL Server back-end, do the same with RavenDB. If you don't mind leaky abstractions, or the project is small enough to not warrant abstracting your data access at all, code accordingly. The main difference with RavenDB is that you're g

Categories : C#

RavenDB LoadAsync. Can't catch exception
The behavior your seeing is valid, and is not because you couldn't catch the exception. It's because the exception was already caught for you. In RavenDB, if you try to load a document that doesn't exist, the Load or LoadAsync methods will return null. They will not throw an exception. When you are debugging, you are seeing that under the hood a WebException is thrown when the HTTP response comes back as 404. That exception is handled. You should see it in the output window as a "First Chance Exception". This is all normal behavior. If you want to check that you can catch exceptions, try something that will actually throw an exception. Perhaps load a document of one type while trying to cast it into another. That will certainly throw an exception.

Categories : C#

RavenDB Query Always Faster Than Load
From what I understand, Load will guarantee to return a result (provided that id exists in the database) whereas Query might not return a result if the indexes haven't yet been updated. You could have a scenario whereby you insert a record, then on the next line try to retrieve that same record using Query and then not get anything back. Load would return a record in this scenario. So I guess the performance degradation you are seeing might be related to the fact that you are querying by index when using Query, whereas Load is hitting the actual data store.

Categories : C#

Custom Field Design with C# and RavenDB
Since you said in comments: ... a Book from a year ago should show the custom fields as of a year ago. There are only two viable options I can see. Option 1 Custom field definitions exist in their own documents. Every book contains a copy of the custom field definitions that apply to that book, along with the selected values for each custom field. They are copied when the book is first created, but could be copied again as your logic sees fit. Perhaps on edit, you might want to take a new copy, potentially invalidating the current selections. Advantages: Self-contained, easy to index and manipulate. Disadvantages: Lots of copies of the custom field definitions. Storage requirements could be very large. Option 2 Use the Temporal Versioning Bundle (disclaimer: I am its author

Categories : C#

Can RavenDB persist documents to a filesystem?
You don't need RavenDB for that. Just use System.IO.File and related concepts. Raven won't work with individual files on disk. It keeps it's own set of files for its index and data stores. Access from other programs is not allowed. What happens in RavenDB, stays in RavenDB. Most people store big files on disk, and then just store a file path or url reference to them in their RavenDB database. Raven also supports the concept of attachments, where the file is uploaded into Raven's database - but then it wouldn't be available as a single file on disk the way you are thinking.

Categories : File

Multiple tests running with RavenDB
Assuming that Controller.Post(testString) is adding a new entry, you probably just have a stale index. In the real world, some natural amount of time would pass between post and query. In unit tests, you don't have that delay, so it's common to provide the following on your index: .Customize(x => x.WaitForNonStaleResults()) This is not something you should do in production. You can read more in the documentation here.

Categories : C#

How to create your own type and use it to store data
The basic definition of a Dictionary is given by Dictionary(Of type1, type2), where types can be anything, that is, primitive types (String, Double, etc.) or ones you create (via Class, for example). Also you can account for them as "individual variables" or inside collections (Lists, Arrays, etc.). Some examples: Dim dict = New Dictionary(Of String, List(Of String)) Dim tempList = New List(Of String) tempList.Add("val11") tempList.Add("val12") tempList.Add("val13") dict.Add("1", tempList) Dim dict2 = New Dictionary(Of String, type2) Dim tempProp = New type2 With tempProp .prop1 = "11" .prop2 = "12" .prop2 = "13" End With dict2.Add("1", tempProp) Dim dict3 = New Dictionary(Of String, List(Of type2)) Dim tempPropList = New List(Of type2) Dim tempProp2 = New

Categories : Vb.Net

Using EclipseLink JPA to store XML type to PostgreSQL
PostgreSQL is annoyingly strict about implicit casts between text-like types like json, xml, etc. The strictly correct solution is to use setObject(the_string, java.sql.Types.SQLXML) when setting the parameter with JDBC. This is difficult through ORM layers, and many ORMs don't seem to understand the SQL/XML types directly. You can tell PostgreSQL to permit the cast from text to xml to be made implicitly by modifying the system catalogs. It isn't ideal, but it'll work. In psql, you can use dC xml to list cats to xml: List of casts Source type | Target type | Function | Implicit? -------------------+-------------------+--------------------+--------------- character | xml | xml | no characte

Categories : Java

Is it possible to store a C data type in a variable?
No, there's no such type that can store a type in standard C. gcc provides a typeof extension that may be useful. The syntax of using of this keyword looks like sizeof, but the construct acts semantically like a type name defined with typedef. See here for detail. Some more examples of the use of typeof: This declares y with the type of what x points to. typeof (*x) y; This declares y as an array of such values. typeof (*x) y[4]; This declares y as an array of pointers to characters: typeof (typeof (char *)[4]) y; It is equivalent to the following traditional C declaration: char *y[4]; To see the meaning of the declaration using typeof, and why it might be a useful way to write, rewrite it with these macros: #define pointer(T) typeof(T *) #define array(T, N) typeof(T [N])

Categories : C

What's the best data type to store 01,02,03 etc. in mySQL?
These look like codes as opposed to numbers, meaning that you are not doing arithmetic operations. If they are codes, the best way to store them is as varchar(2) or char(2) types. If you are treating them as numbers (that is, doing any arithmetic operations), then you should store them as integers (small integers) and append the leading zeros on output. EDIT: It is very important to distinguish between strings of digits that are just that -- strings that contain digits -- and actual numbers. There are many examples of such strings that you definitely want to store as character strings. Four that come to mind are telephone numbers, American zip codes, account numbers (the account number at my bank starts "057" and the "0" is really, really, really important), and (for the most part) t

Categories : Mysql

Query ravendb without defining a model class?
I believe you can use database commands (Query) to accomplish what you are trying, as long as you know the name of the document collection you are trying to get. See here for more information. QueryResult sites = store.DatabaseCommands.Query( "Sites/ByTitle", new IndexQuery { Query = "Title:CN*" }, null);

Categories : C#

Why my query doesn't return any results from RavenDB?
You should check that the index "Raven/DocumentsByEntityName" is defined for the target database, and that your document has the correct metadata information. The metadata should have a line like this: "Raven-Entity-Name": "CountryRegion" If this does not help, please also post the ravendb version you are using. A fiddler trace might also be helpful.

Categories : C#

RavenDB - How do I query on both an object's properties and its children
First, we'll tackle the index, note that child keys are prefixed with Children_ (required by Raven): public class Objekt_ByCodeAndChildren : AbstractIndexCreationTask<Objekt> { public Objekt_ByCodeAndChildren() { Map = objekts => from objekt in objekts from child in objekt.Children select new { objekt.Code, Children_Role = child.Role, Children_Place = child.Place }; } } The query itself: session.Query<Objekt, Objekt_ByCodeAndChildren>() .Where(o => o.Code == "1" && o.Children.Any(c => c.Role == "A" && c.Place =

Categories : C#

RavenDb Constucting complex viewmodel using MultiMap?
The best idea here would to not have them as separate documents. A single document can contain all of this. In other words, the structure you've described as the view model can be stored directly into the database as your document structure. Of course, that means that you will always be retrieving the document by the top-level id. Without additional context of what these nodes represent, it's hard to say if that is appropriate or not. Also, it looks like you are getting good feedback from this thread on the RavenDB Google Group already. Try not to cross-post in the future. If you want something very specific, then StackOverflow is great. If you need more of a general how-to or debate of ideas, then use the Google Group. If you can edit your question to be more specific, perhaps sh

Categories : C#

Query over a collection of composite keys in RavenDB using C#
There are multiple ways to do this, but the easiest way would be to provide your own document key instead of using the one Raven generates. This is often referred to as using "structured" or "semantic" keys. Here is a good description of the general technique. Simply add a string Id property to your class. You want the document key to reflect the unique key you described, so probably it should have a value such as "reports/2013/Q1/bob" (but you might want a more unique value for user). You can let .Net construct the key for you in the property getter, such as: public class Report { public string Id { get { return string.Format("reports/{0}/Q{1}/{2}", Year, Quarter, User); } } public string User { get; set; } public int Quarter { get; set; } public int

Categories : C#

how to inject ravendb instance through IDatabaseFactory interface?
If your Raven client does not have the interface already you will need to craft it yourself. You will need to make a factory instance implementing all of the members on that interface and pass it across.

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.