I am working on a RavenDB query on a type that is built in run time so I can't use generic methods like Query<>. I have to do this using DocumentStore.DatabaseCommands.Query something like this :
documentStore.DatabaseCommands.Query("Raven/DocumentsByEntityName", new IndexQuery{Query = "Tag : MyDocuments"},null);
So far so good unless this way I am getting Json objects and I want to transform them into another type.I realized that IndexQuery has a ResultsTransformer property but I don't know how to use it and couldn't find any documentation for this particular use of IndexQeury neither.
So the question is how I can transform the results into another type?
Set the ResultsTransformer property of the IndexQuery
UPDATE
To use ResultsTransformer property of IndexQuery one should create a ResultTransformer using AbstractResultTransformerCreationTask or DocumentStore.DatabaseCommand.PutTransformer (that accept a raw string to create a transformer) then he can set ResultsTransformer property of the IndexQuery to the name of this transformer.
Related
Using Roslyn for VB.Net I can get the Type of an Expression using the code below.
Dim ExpressionType As TypeInfo = SemanticModel.GetTypeInfo(ForEachStatement.Expression)
If the expression is a collection (List, Dictionary, Array, Collection...) how can I find out what is in the collection? For the example below I want to find DocumentIdAndRoot
Dim docs As List(Of DocumentIdAndRoot) = Await RemoveParameterAsync(document, parameter, root, cancellationToken)
If your question is specific to foreach, then you should use SemanticModel.GetForEachStatementInfo(), which returns a ForEachStatementInfo with all the necessary information.
What you could do is take the TypeInfo you get, and look at the ImplementedInterfaces property. One of those would be IEnumerable or ICollection, and from there you could look at what the generic parameter is.
If you do have a ForEach involved somewhere, you're still better off using Tamas' approach, since that will correctly implement the language rules there.
In the auto-generated resource designer file, there are properties for each resource. The property calls "GetString" which returns the string value. I would like to override this getstring function so I can do logic to see if I need to retrieve this value or a different value. I can't figure out how to do this because the designer file is auto-generated.
Public ReadOnly Property General() As String
Get
Return ResourceManager.GetString("General", resourceCulture)
End Get
End Property
For example, in my version of the GetString function, I would check the key passed in ("General") and see if there is a custom value for this key in a database. If the custom value exists, I would use that value. If the custom value does not exist, I would call the base GetString function to get the Resource value. I'd like to use the built in Resource class for this because then in my code I can just use "#Resources.General" and take advantage of the auto-complete functionality that already exists.
Refer to ASP.NET Resourcemanager to read local .resx. It's in C# but you can just convert it over. It isn't 100% of what you are looking for but shows a way of overriding in which you may be able to adjust to work with your needs.
Can someone tell me why in NHibernate mapping we can set access="field.camelcase", since we have access="field" and access="property"?
EDIT: my question is "why we can do this", not "what does it mean". I think this can be source of error for developper.
I guess you wonder what use field.camelcase have when we can do the same with just field? That's true, but that would give (NH) properties unintuive names when eg writing queries or reference the property from other mappings.
Let's say you have something you want to map using the field, eg
private string _name;
public string Name { get { return _name; } }
You sure can map the field using "field" but then you would have to write "_name" when eg writing HQL queries.
select a from Foo a where a._name = ...
If you instead using field.camelcase the data, the same query would look like
select a from Foo a where a.Name...
EDIT
I now saw you wrote "field.camelcase" but my answer is about "field.camelcase-underscore". The principles are the same and I guess you get the point ;)
the portion after the '.' is the so called naming strategy, that you should specify when the name you write in the hbm differ from the backing field. In the case of field.camelcase you are allowed to write CustomerName in the hbm, and NHibernate would look for a field with name customerName in the class. The reason for that is NHibernate not forcing you to choose a name convention to be compliant, NH will works with almost any naming convention.
There are cases where the properties are not suitable for NH to set values.
They may
have no setter at all
call validation on the data that is set, which is not used when loading from the database
do some other stuff that is only used when the value is changed by the business logic (eg. set other properties)
convert the value in some way, which would cause NH performing unnecessary updates.
Then you don't want NH to call the property setter. Instead of mapping the field, you still map the property, but tell NH to use the field when reading / writing the value. Roger has a good explanation why mapping the property is a good thing.
I am using Linq to Sql that generated a data contract for a table. I have a date field in that table which is a non-nullable field. I need to override the auto generated property of the date field to return a specific value, something like
Get
if_dt<>date.minvalue
return _dt
else
return string.empty
End Get
Is it possible to override an autogenerated property in the designer.vb file using a partial class? I dont want to create a new property as it is currently being accessed in n number of places and I dont want to change it in every place.
No, you'll need to modify the .designer file or inherit from it and change the behavior of that property (but I guess the auto-generated property won't be virtual so you'll need to edit it anyway)
I want to be able to specify the properties to get populated/updated in the linq expression.
Something in the following fashion:
Proxy.UpdateEmployee(List<string> propertiesNames)
Proxy.GetEmployee() //inside the method populate only certain properties
The return values must be of known type(no anonymous types accepted).
DLINQ enable to select by specifying properties' names but the result is IQueryable interface and I'm unable to AsEnumerable() it in order to build the known type query afterwards.
You have to use reflection to modify instance properties by name.
So wherever you're updating your object with LINQ you need to do something like this:
foreach (string propName in propertiesNames)
{
PropertyInfo prop = this.GetType().GetProperty(propName);
prop.SetValue(valueForProp);
}