Format exception - RavenDB LINQ query - linq

I am getting a input string format error in the following bit of code... While debugging code, this runs as a single line of code and so I am not able to dig deep into what might be causing the format exception.. can any one please point to me what I am doing wrong.. thank you.
Exception:
FormatException was unhandled by user code:
"Input string was not in correct format"
Code:
store.DatabaseCommands.UpdateByIndex("Movies/NewIndexName",
new IndexQuery
{
Query =
string.Format("Status:Released AND IsDeleted:false AND ReleaseDate:{* TO {0}}",
DateTools.DateToString(new DateTime(2012, 4, 3),
DateTools.Resolution.MILLISECOND))
},
new[]
{
new PatchRequest
{
Type = PatchCommandType.Modify,
Name = "Status",
Value = "TestingReleased"
}
}, allowStale: false);

The problem is inside string.Format, You need the value to be:
{{* TO {0}}}
In other words, you need to escape the { }

Related

Pushing empty DataTable into SQL Query as structured parameter

I recently bumped into an issue of raising an exception "Type structured needs to have at least one field" when pushing empty DataTable to an SQL query as structured parameter.
I basically have something like this (MyTestType is defined on the SQL server):
DataTable dt = new DataTable("test")
dt.Columns.Add("id", typeof(int));
try {
using(SQLConnection conn = new SQLConnection("{ConnectionString}"))
{
conn.Open();
using(SQLCommand comm = new SQLCommand("SELECT * FROM #TestDataTable", conn))
{
comm.Parameters.Add(new SQLParameter("#TestDataTable", SqlDbType.Structured){ Value = dt, TypeName = "dbo.MyTestType" });
using(SQLDataReader reader = comm.ExecuteReader())
{
while(reader.Read())
{
...
}
}
}
}
}
catch(Exception(ex))
{
throw(ex)
}
finally
{
conn.Close()
}
The thing is, I might end up with or without any data in my DataTable that I pass as a parameter into the query and the query really doesn't mind if the provided DataTable is empty, it just does some joins and if they equal to nothing, then nothing happens. Problem is that C# won't let it pass into the query and I really don't want to provide some "blank" DataRow in case it's empty just so it gets over it. That is not a clean solution.
Anyone any idea? Thanks in advance. PS: if the code has some issue, just quick fix it, I typed it from the top of my head.

How can I execute an instance query in graphql-fhir?

This issue is migrated from a question on our Github account because we want the answer to be available to others. Here is the original question:
Hello,
Following is the InstanceQuery I tried
http://localhost:3000/3_0_1/Questionnaire/jamana/$graphql?query={id}
I am receiving back response as Cannot query field \"id\" on type \"Questionnaire_Query\"
So what is the right format I should try ?
https://build.fhir.org/graphql.html has a sample as http://test.fhir.org/r3/Patient/example/$graphql?query={name{text,given,family}}.Its working in their server. I cannot get the response When I try similarly in our graphql-fhir.
Original answer from Github:
We are using named queries since we are using express-graphql. I do not believe that is valid syntax. Also, the url provided does not seem to work, I just get an OperationOutcome saying the patient does not exist, which is not a valid GraphQL response.
Can you try changing your query from:
http://localhost:3000/3_0_1/Questionnaire/jamana/$graphql?query={id}
to this:
http://localhost:3000/3_0_1/Questionnaire/jamana/$graphql?query={Questionnaire{id}}
When writing the query, you need to provide the return type as part of the instance query. You should get a response that looks like similar to this(if you have implemented your resolver you will have data and not null):
{
"data": {
"Questionnaire": {
"id": null
}
}
}
and from a later comment:
If you are getting null then you are doing it correctly, but you haven't wrote a query or connected it to a data source. You still need to return the questionnaire in the resolver.
Where you are seeing this:
instance: {
name: 'Questionnaire',
path: '/3_0_1/Questionnaire/:id',
query: QuestionnaireInstanceQuery,
},
You are seeing the endpoint being registered with an id parameter, which is different from a GraphQL argument. This is just an express argument. If you navigate to the questionnaire/query.js file, you can see that the QuestionnaireInstanceQuery query has a different resolver than the standard QuestionnaireQuery. So in your questionnaire/resolver.js file, if you want both query and instance query to work, you need to implement both resolvers.
e.g.
// This is for the standard query
module.exports.getQuestionnaire = function getQuestionnaire(
root,
args,
context = {},
info,
) {
let { server, version, req, res } = context;
// Do query and return questionnaire
return {};
};
// This one is for a questionnaire instance
module.exports.getQuestionnaireInstance = function getQuestionnaireInstance(
root,
args,
context = {},
info,
) {
let { server, version, req, res } = context;
// req.params.id is your questionnaire id, use that for your query here
// queryQuestionnaireById does not exist, it is pseudo code
// you need to query your database here with the id
let questionnaire = queryQuestionnaireById(req.params.id);
// return the correct questionnaire here, default returns {},
// which is why you see null, because no data is returned
return questionnaire;
};

Query works Mutations fail: Expected non-null value, resolve delegate return null

I have a GraphQL .Net Core server and queries resolve wonderfully. Mutations however are failing with this error.
"message": "Expected non-null value, resolve delegate return null for \"$GraphQLCore.Types.SInputType\"",
I understand that you do not reuse your query types for mutations and I have created separate types but I'm still missing something.
public class SInputType : InputObjectGraphType
{
public SInputType()
{
Field<IntGraphType>("sid");
...etc
}
}
public class SUpdateMutation : ObjectGraphType
{
MutationMock mm = new MutationMock();
public SUpdateMutation()
{
Field<SInputType>(
"createSrecord",
arguments: new QueryArguments(new QueryArgument<SInputType>
{ Name = "sticker"}),
resolve: context => {
var _stik = context.GetArgument<SModel>("stick");
return mm.StockMutation(stick);
});
}
}
Everything I come up with on Goggle is related to NOT using a InputObjectGraphType but I am and from the examples I see I am using it correctly???
So any input or pointers would be greatly appreciated.
TIA
The error was misleading me.
That error throws when you aren't using the InputObjectGraphType BUT it also throws when you forget to add your new InputType to the sevicesCollection.
Adding this line fixed it.
services.AddSingleton<SInputType>();

sys_id arrays to is one of not displaying records on my report

I am not able to display records on my report.
Report Source: Group Approval(sysapproval_group) table
Condition:Sys Id - is one of - javascript: new GetMyGroupApprovals().getSysIds();
Script Include : MyGroupApproval
Note : Active is checked, Accesible is all application score & Client callable unchecked
var GetMyGroupApprovals = Class.create();
GetMyGroupApprovals.prototype = {
initialize: function() {
},
getSysIds : function getMyGroupMembers(){
var ga = new GlideRecord('sysapproval_group');
ga.addQuery('parent.sys_class_name', '=', 'change_request');
ga.query();
gs.log("TotalRecords1 Before:: " + ga.getRowCount());
var sysIdArray = [];
while(ga.next()){
sysIdArray.push(ga.sys_id);
}
return sysIdArray;
},
type: 'GetMyGroupApprovals'
};
Kindly note that I have to achieve with script approach. I am not able to get records on my report.
This line is probably causing unexpected behavior:
sysIdArray.push(ga.sys_id);
ga.sys_id returns a GlideElement object, which changes for each of the iterations in the GlideRecord, so the contents of sysIdArray will just be an instance of the same object for each row in the result set, but the value will just be the last row in the set.
You need to make sure you push a string to the array by using one of the following methods:
sysIdArray.push(ga.sys_id+''); // implicitly call toString
sysIdArray.push(ga.getValue('sys_id')); // return string value
Quick suggestion, you can use the following to get sys_ids as well:
sysIdArray.push(ga.getUniqueValue());

Value cannot be null. Parameter name: source in MVC listbox

I have found plenty of posts about this, but none of them are solving my issue. My code right now:
#Html.ListBox("SelectedNewsletter", Model.Newsletters)
and
public MultiSelectList Newsletters
{
get
{
return new MultiSelectList(
new[]
{
// TODO: Fetch from your repository
new { Id = 1, Name = "item 1" },
new { Id = 2, Name = "item 2" },
new { Id = 3, Name = "item 3" },
},
"Id",
"Name"
);
// return new MultiSelectList(PromoNewsletter.All, "IdString", "Display");
}
}
As far as I can see, it's all hard coded now, and it still gives the same error. I want to do a ListboxFor, but I am trying to just get a listbox to work. I have replaced my int id with a string representation, based on advice I found elsewhere, but now I don't see what else I can do. It just plain is not working, even with all hard coded values and not binding to a property on my ViewModel. Where am I going wrong ?
The error is occurring because you have a property in the Model or ViewData/ViewBag with the name SelectedNewsletter.
Give a different name for the ListBox if you can't rename that property.
UPDATE:
After little more experimenting I figured out that the problem is you may be setting an integer value to the SelectedNewsletter that is somewhere in the ViewData/ViewBag or Model.
You can set the values that has to be selected in the ListBox as a string or array of strings to the SelectedNewsletter.
i.e SelectedNewsletter = "1";
or
SelectedNewsletter = new[] { "1", "3" };
You can also use strongly typed helper to make things easy,
#Html.ListBoxFor(m => m.SelectedNewsletter, Model.NewsLetters);

Resources