Tag: c#

Sql Server Session Context Limit

We are having issues setting and clearing out session context values. We receive the following error: The value was not set for key X because the total size of keys and values in the session context would exceed the 1 MB limit We are using asp.net core and dapper for our data access. When opening […]

error in Data access mvc using entity framework

Error message is : Invalid column name ‘EmployeeId’ Invalid column name ‘EmployeeId’ Invalid column name ‘City’. { EmployeeContext employeeContext = new EmployeeContext(); Employee employee = employeeContext.Employees.Single(emp => emp.EmployeeId == id); //This line is causing the error } But I got exact same database table with all matching columns, why it said I have invalid columns? […]

Entity Framework 6 Handle Transaction At Database Level

I have a stored procedure that uses transactions at a database level (the transactions are handled within the stored procedure itself). This means I need to tell Entity Framework not to handle transactions. Now using database first model I can import the stored procedure and have an auto generated context class that looks like the […]

Parameterizing a ServiceStack custom SQL query

I have the following custom SQL Query with OrmLite: var results = db.Select<Tuple<Customer,Purchase>>(@”SELECT c.*, 0 EOT, p1.* FROM customer c JOIN purchase p1 ON (c.id = p1.customer_id) LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND (p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id)) WHERE p2.id IS NULL;”); What is the […]

how to write a single sql query based on combobox selection?

I have a winform in which user input values through a combobox. I am assigning combobox value to search db. If there is no selection then the SQL server query should not use that column to filter. example – if (string.IsNullOrEmpty(combobox1.text)) { …..Select * from country } else if (combobox1.selectedindex > -1) { ….Select * […]

How to execute and return value form a stored procedure inside FluentNHibernate Mapping?

Well, I have a ClassMap like this for my mapping in FluentNHibernate public class AbNopCommereceMap : ClassMap<AbNopCommerece> { public AbNopCommereceMap() { Table(“AbNopCommerece”); Id(d => d.Id).CustomSqlType(“BIGINT”).GeneratedBy.Native(); Map(d => d.Name).CustomSqlType(“NVARCHAR(100)”).Unique().Not.Nullable(); Map(u => u.PublisherName); Map(u => u.Author); Map(u => u.Country); Map(u => u.LastModifiedByFullName).Formula(“(SELECT b.FirstName +’ ‘+ b.LastName FROM Users b WHERE b.Id=CreatedBy)”); Map(d => d.IsActive); Map(d => d.IsDeleted); […]

Increment DateTime value based on total number of days

When a user adds a class they choose the start date and the end date of the class. I have been able to calculate the value between the end date and start date. I was able to create a For loop to insert a row into the Class table for each individual day the class […]

C# Entity Framework: making sure each entry is unique

I’m making an API call with C#, getting back a JSON, breaking it down into nested objects, breaking each object into fields and putting the fields into an SQL Server table. There is one field (OnlineURL) which should be unique. What is an efficient way of achieving this goal? I currently make a database call […]

SQL Server & C# – How can I check if a varbinary(max) file i'm uploading already exists in a table?

I am storing files in a table in SQL Server, in the following format: FileID – int (auto increment), FileName – VarBinary(MAX), FileData – VarBinary(MAX). What I would like to do is – by uploading a new FileName & FileData as parameters, return the first FileID where the FileName & File Data match, like so: […]

Entity Framework: Reusing foreign key

I’m refactoring someone else’s code involving EF6, code-first. I am trying to reuse database columns so that they are involved in more than one foreign key relationship. I am aware that by doing this, I am denormalizing my schema, but in so doing, it will allow me to make more direct relationships between models that […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.