Cannot set htmlAttribute parameter - asp.net-mvc

I'm adding in the object htmlAttributes parameter and getting an error :
"Error 41 Invalid anonymous type
member declarator. Anonymous type
members must be declared with a member
assignment, simple name or member
access"
Response.Write(Html.CheckBox("chkStatus", item.Value) + " " + item.Text + "<br />");
Response.Write(Html.CheckBox("chkStatus", item.Value,new {checked=true}) + " " + item.Text + "<br />");
I get the error when i try to add the "new {checked=true} part.
Cannot find an example of setting parameter in c# code online, cheers

I think checked is a keyword. Try putting an # in front:
new { #checked = true }

Related

Neo4j Custom Procedures: How to pass query parameters?

I am trying to write a custom procedure for the Neo4J GraphDB in accordance to the documentation and the there referenced template. The procedure should ultimately generate a graph projection using the GDSL, for nodes with a certain label that is provided as a procedure parameter. For this it is, of course, necessary to pass the label to the query that is to be executed within the custom procedure. However, I cannot seem to find out how to pass parameters to a query string.
#Procedure(value = "custom.projectGraph")
#Description("Generates a projection of the graph.")
public Stream<ProRecord> projectGraph(#Name("graph") String graph) {
Map<String, Object> params = Map.of (
"graph", graph
);
return tx.execute("call gds.graph.project.cypher(\"$graph\", "
+ "\"MATCH (n:$graph) return id(n) as id\", "
+ "\"MATCH (src:$graph)-[]-(dst:$graph) "
+ "RETURN id(src) AS source, id(dst) AS target\") "
+ "YIELD graphName", params)
.stream()
.map(result -> (String) result.get("graphName"))
.map(ProRecord::new);
}
public static final class ProRecord {
public final String graphName;
public ProRecord(String graphName) {
this.graphName = graphName;
}
}
This code, unfortunately, does not work as intended, throwing the following exception:
Invalid input '$': expected an identifier
I did copy the syntax of prefixing placeholders with $-characters from other examples, as I could not find any hints on the passing of query parameters in the JavaDoc of the library. Is this even the correct documentation for custom neo4j procedures? Am I possibly using the wrong method here to issue my queries? It'd be very kind if someone could lead me into the right direction on that matter.
In general, when you use a string parameter the $param is automatically quoted, unlike the String.format for example.
Therefore there are 2 problems in your query:
\"$graph\" : in this case you are doubly quoting the parameter, try to write only $graph instead
Things like this n:$graph cannot be done unfortunately, the neo4j parameter handling is not able to recognize where to quote and where not, so you could use String.format or concat string with parameters (e.g. "MATCH (n:" + $graph + ") return id(n)...").
So, in short, this piece of code should work in your case:
return tx.execute("call gds.graph.project.cypher($graph, " +
"'MATCH (n:' + $graph + ') return id(n) as id', " +
"'MATCH (src:' + $graph + ')-[]-(dst:' + $graph + ') RETURN id(src) AS source, id(dst) AS target') YIELD graphName",
params)
.stream()
.map(result -> (String) result.get("graphName"))
.map(ProRecord::new);

WIQL query to get all item under a workitem

I am looking for a query where i can return all work items and their relation from a area path.
for example : project 1
i need all Featured all Userstories mapped to it all workitem and Bug mapped to userstories,
in short if i took a bug from the object i need somthing like parent id where i can match with the userstory.
string query1 = " SELECT * FROM WorkItemLinks " +
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
which throwing an error like below
An exception of type 'Microsoft.TeamFoundation.WorkItemTracking.Client.ValidationException' occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll but was not handled in user code
Additional information: TF51005: The query references a field that does not exist. The error is caused by «[System.IterationPath]».
when i checked the dll's are refereed correctly and when i re wrote the query like this the query is working fine
string query = " SELECT * FROM WorkItems"+
" WHERE ( [System.IterationPath] Under 'iteration1' )" +
//" AND ([System.State] = 'Active' OR [System.State] = 'Assessed' ) "+
//" AND ( [Microsoft.VSTS.Scheduling.StartDate] <= '09/13/2017' AND [Microsoft.VSTS.Scheduling.FinishDate] >= '09/13/2017' )"+
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
but this query result does not give the relation ship that if a work item mapped as a child to other i need parent id in the work item object. how to get that. Thanks in advance.
You can try below query:
Install Nuget Package Microsoft.TeamFoundationServer.ExtendedClient for the project.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
namespace _0925_WIQL
{
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
new Uri("http://server:8080/tfs/CollectionLC"));
WorkItemStore workItemStore = (WorkItemStore)tpc.GetService(typeof(WorkItemStore));
string query1= " SELECT * FROM WorkItemLinks " +
" WHERE ( Source.[System.IterationPath] Under 'TeamProject\\Iteration 1' )" +
" AND ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward' )" +
" ORDER BY [Microsoft.VSTS.Scheduling.StartDate]";
Query query = new Query(workItemStore, query1);
WorkItemLinkInfo[] witLinkInfos = query.RunLinkQuery();
foreach (WorkItemLinkInfo witinfo in witLinkInfos)
{
.......
}
Besides, you can also use Wiql Editor. If you want to get all the parent workitems (IDs) from a specific child work item (ID), you can use below WIQL:
SELECT
[System.Id],
[System.WorkItemType],
[System.Title],
[System.AssignedTo],
[System.State]
FROM workitemLinks
WHERE ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward')
AND ([Target].[System.Id] = 25)
ORDER BY [System.Id]
MODE (Recursive, ReturnMatchingChildren)

How do you pass a variable to #{ } to build a Query as only global variable is visible

I cannot pass the variable the create for the table is below for testing database is KSI, using MS SQL EXPRESS. The OPen and query I believe used the Webmatrix calls
It does not matter what the statements do, it's about passing visibility of the variables.
This is just supposed to read sdata and pass it to selcmd.
Here is the problem with this code, the variable selcmd does not exist in this context.
Global_selcmd does but I am unable to pass selcmd to the code after the #{ sign, only works with global variable.
selcmd error CS0103: The name 'selcmd' does not exist in the current context
<!DOCTYPE html>
<form name="myForm" method="POST">
Created by: <input type="text" name="sdata" style="width: 434px"
size="25"><br>
<input type="submit" value="SUBMIT">
</form>
#{
var db = Database.Open("KSI");
// swap the following comment lines
//var selcmd = "INSERT INTO [KSI].[dbo].[Proposal] ([ProposalNo],
[EntDate]) VALUES ('" + sdata + "', GETDATE() )";
var selcmd = "INSERT INTO [KSI].[dbo].[Proposal] ([ProposalNo],
[EntDate]) VALUES ('" + "tst2text" + "', GETDATE() )";
//alert("EXECUTING: b4 " + selcmd);
db.Query(selcmd);
//alert("DONE: " + selcmd);
}

Cannot insert explicit value for identity column in table 'OS_Mailinglist1' when IDENTITY_INSERT is set to OFF

Can anyone help me why I am getting this error? Thanks in advance..
Cannot insert explicit value for identity column in table
'OS_Mailinglist1' when IDENTITY_INSERT is set to OFF. Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details:
System.Data.SqlClient.SqlException: Cannot insert explicit value for
identity column in table 'OS_Mailinglist1' when IDENTITY_INSERT is set
to OFF.
Source Error:
Line 312: cmd.ExecuteNonQuery();
Line 313: ClientScript.RegisterStartupScript(this.GetType(), "alert",
"alert('Successsfully Registered your Email ID and Area of
interest.');", true);
Code behind page that shows error:
else
{
Util.SetConnection();
Util.sql_con.Open();
cmd = new SqlCommand("insert into offsale.OS_Mailinglist1(UserName,Area_Of_Interest,Mail_Pwd)values('" + txtEmail.Text.ToString() + "' ,'" + arrvalues + "','" + ViewState["pwd"].ToString () + "')", Util.sql_con);
// cmd = new SqlCommand("insert into offsale.OS_Mailinglist1(UserName,Area_of_interest,Mail_Pwd)values('" + txtEmail.Text.ToString() + "' ,'" + arrvalues + "','" + passwrd.Text.ToString () + "')", Util.sql_con);
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Successsfully Registered your Email ID and Area of interest.');", true);
Util.sql_con.Close();
you are trying to insert a value into an identity column. to explicitly allow this you have to to turn the global IDENTITY_INSERT session value on.

Reference ENUM description when building selectList for dropdown list control

I have a form view model class that populates Select Lists for use by my views. Below is an extract from a section that creates a SelectList. The problem is that its a lookup table containing 2 other keys
var waterIndicatorValues = waterIndicator
.OrderBy(u => u.WaterIndicatorDescription)
.Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToString() + "] " + u.HazardTypeId.ToString()));
this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);
Instead of UnitTypeId and HazardTypeId I want the text descriptions associated with those Id's. So i'd like my code to look like this :
var waterIndicatorValues = waterIndicator
.OrderBy(u => u.WaterIndicatorDescription)
.Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToDescription() + "] " + u.HazardTypeId.ToDescription()));
this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);
This code returns error "Method 'System.String ToDescription(System.Enum)' has no supported translation to SQL."
Any comments/help greatly appreciated
ENUM for UnitTypeId:
using System.ComponentModel;
namespace Emas.Model.Enumerations
{
/// <summary>
/// Defines the Unit Types.
/// </summary>
public enum UnitType
{
[Description("- Please Select -")]
Blank = 0,
[Description("kWh")]
kWh = 1,
[Description("m3")]
m3 = 2,
[Description("litres")]
litres = 3,
[Description("Kg")]
Kg = 4,
[Description("Unit(s)")]
Unit = 5,
}
}
You can't use extension methods within LINQ that pulls data from the database as it cannot be convert this extension code into SQL. You can however use ToArray() or ToList() to trigger the database hit and then use your extension methods on the result in memory instead.
Update:
Based on what you're trying to achieve in your updated code, I think this article may have the answer you need. You'll need to cast to the enum type too of course.
Update 2:
Converting into memory using ToList() before doing the select with extensions should work ok like below:
var waterIndicatorValues = waterIndicator
.OrderBy(u => u.WaterIndicatorDescription)
.ToList()
.Select(u => new KeyValuePair<int, string>(u.WaterIndicatorId, u.WaterIndicatorDescription + " [" + u.UnitTypeId.ToDescription() + "] " + u.HazardTypeId.ToDescription()));
this.WaterIndicatorList = new SelectList(waterIndicatorValues, "Key", "Value", water.WaterIndicatorId);

Resources