static void Main(string[] args) { Orm.Register <Cat>(new CatConverter()); // Change the connectionstring below, OR create a login role "for_samples", with password "sample" // Followed by: // grant all on cats to for_samples // grant all on cats_id_seq to for_samples var connection = new Stormy.Connection(new Npgsql.NpgsqlConnection("Server=localhost;User Id=for_samples;Password=sample;Database=stormy")); var Tom = new Cat() { Name = "Tom" }; var Jerry = new Cat() { Name = "Jerry" }; // Insert these cats using the mapper defined above connection.Insert(Tom); connection.Insert(Jerry); // And they have auto-numbered ID's Console.WriteLine("Tom: id={0}, Jerry: id={1}", Tom.Id, Jerry.Id); var cats = connection.Select <Cat>("select * from cats"); }
static void Main(string[] args) { bool exists = System.IO.File.Exists(filename); var connection = new Stormy.Connection( new SQLiteConnection(String.Format("Data Source={0}", filename))); // Create and fill the datamodel, // if the SQLite database did not exist before if (!exists) { CreateDataModel(connection); } var cats = connection.Select <Cat>("select * from cats", (reader) => new Cat() { Name = reader["name"].ToString(), Weight = Double.Parse(reader["weight"].ToString()) }); foreach (var cat in cats) { System.Console.WriteLine("Cat {0} is {1}", cat.Name, cat.Weight); } }
static void Main(string[] args) { // 3. Register the mapper, such that CatMapper is used for model Cat Orm.Register <Cat>(new CatMapper()); // 4. Create the connection (connection strings are just ADO.NET) var connection = new Stormy.Connection(new SqlConnection( @" Data Source=localhost\SQLEXPRESS; Initial Catalog=stormy; Integrated Security=SSPI; ")); // 5. Get list of models (here Cats) using plain SQL statements foreach (var cat in connection.Select <Cat>("select * from cats")) { System.Console.WriteLine("Cat {0} is {1}", cat.Name, cat.Weight); } }
static void Main(string[] args) { // 3. Register the mapper, such that it is used for model City Orm.Register <City>(new CityMapper()); // 4. Create the connection (connection strings are just ADO.NET) var connection = new Stormy.Connection(new SqlConnection( @" Data Source=localhost\SQLEXPRESS; Initial Catalog=stormy; Integrated Security=SSPI; ")); // 5. Get list of models (here Cities) using SQL var cities = connection.Select <City>("select * from cities"); foreach (City city in cities) { // Just use the SqlGeometry methods such as STX, STY, STIntersects, etc. System.Console.WriteLine("City {0} location lat={1}, lon={2}", city.Name, city.Location.STY, city.Location.STX); } }