I have this code which is working fine and I update a value if exists or insert if not With this code I manage to do the work with only one query to the SQL, but I was wondering if there is an easier or more elegant way to do it. For example if I could use linq and lambda
Tag: c#
Select items with the same foreign key
I have a question regarding Linq in C#. Let’s say that I have 3 tables “Company”, “Employee” and “Job”. Company ——– Id – int (PK) Name – string Employee ——– Id – int (PK) CompanyId – int …
How to replace columns in a Queryable in a generic fashion without executing the Queryable
As an example, I have a Product entity, a ProductViewModel and a Label entity. Two of my product properties correspond to a label code rather than an actual value. So for example a Product’s Name is “…
system.linq.enumaerable+<Cast… in combobox C#
I have a SQL query that reads string data from a SQL Express DB (Changing over to Azure). Once the data is retrieved, I read it into an array and then display the contents of the array in a combo-box. i am not receiving any error however, in the combo-box, an extra field is displayed and I cannot fgure out
How to fix “Incorrect syntax near ‘)'”. when there is no ) in the query
I am attempting to run a query against my database using Dapper, however, an exception is being thrown. The message of the exception is Incorrect syntax near ‘)’ The part of this that is confusing to me is that I have no right parens in my entire query. It used to have some, but I have been simplifying it until
The INSERT statement conflicted with the FOREIGN KEY constraint in Entity framework core, 2 tables in single statement
I have following 2 classes. public partial class Query { public int Id { get; set; } public virtual QueryGroup QueryGroup { get; set; } } public partial class QueryGroup { public int Id {…
PostgreSQL, Npgsql returning 42601: syntax error at or near “$1”
While passing PostgreSQL command following error 42601: syntax error at or near “$1” Answer After some testing I found that only table values can be passed as parameter not table name and column name. So I changed code like this
How can I convert this sql query that reorders items in a database to linq?
I currently have a table where an item has a new order based on a column it’s being sorted by. The goal of the sql statement is to reorder the table based on that sort column. The SQL Command …
C# Error : Unable to insert record in SQL
Please pardon my knowledge on C# as I am very new to it,I am unable to insert a record in SQL and getting the below error while insert image to SQL. Error : Object reference not set to an instance …
Using LINQ to fill a boolean with true or false based off of condition
I am performing a linq query to grab some data from the DB. Here is my linq: The main 2 tables I am concerned with here are JobRequest and JobRequestParameters… JobRequest table has 13 records (but not all jobs have parameters). JobRequestParameters table only has 4 records. They are joined on by PkJobRequestId. JobRequestParameters has a pkJobParameterId IF and only