Just a quick code sample:
string sql = "INSERT INTO Users (Name) VALUES (@Name); select last_insert_rowid()"; long id = connection.Query<long>(sql, user).First();
Software development blog
Just a quick code sample:
string sql = "INSERT INTO Users (Name) VALUES (@Name); select last_insert_rowid()"; long id = connection.Query<long>(sql, user).First();
Dapper is great, but the documentation is definitely lacking..
I needed to construct dynamic query, with optional parameters. Tried an approach with ExpandoObject, which didn’t work. I guess I could have created a dedicated object which would hold all possible parameters, but it seems.. wrong.
So on a dapper’s tests page (which, I guess, is the documentation) found a DynamicParameters object – exactly what I needed.
This is a quick sample:
public User[] Get(UserFilter filter) { string sql = "SELECT Id, Name, Age FROM Users"; using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { connection.Open(); DynamicParameters parameters = new DynamicParameters(); sql += " WHERE 1=1"; if (filter.Id.HasValue) { sql += " AND Id = @id"; parameters.Add("id", filter.Id.Value); } if (filter.Age.HasValue) { sql += " AND Age = @age"; parameters.Add("age", filter.Age.Value); } // etc var users = connection.Query<User>(sql, parameters).ToArray(); return users; }
If you see this exception on your sharepoint site – open your master page in Sharepoint Designer (!), and find a line that reads “<%@ Register TagPrefix=”wssuc” TagName=”Welcome” src=”~/_controltemplates/Welcome.ascx” %>“.
Make sure the tilde isn’t missing from src attribute (if it’s “src=”/_controltemplates/Welcome.ascx”” – this is the issue).
We’re storing session state in SQL Server. So I ran the aspnet_regsql command (aspnet_regsql.exe -S <db_server> -E – ssadd -sstype c -d <db_name>), which created the correct table, but still was getting ” Unable to use SQL Server because ASP.NET version 2.0 Session State is not installed on the SQL server” exception.. Long story short – make sure your user is an owner of a database you just created – it helps.
The error message really is wrong..
at sharepointlogviewer.codeplex.com. Really makes it easier to look up things.