This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| | 0 values | 1 value | > 1 value | |
| FirstOrDefault | Default | First value | First value | |
| SingleOrDefault | Default | First value | Exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mapper.CreateMap<Source, Destination>(); | |
| var sources = new[] | |
| { | |
| new Source { Value = 5 }, | |
| new Source { Value = 6 }, | |
| new Source { Value = 7 } | |
| }; | |
| IEnumerable<Destination> ienumerableDest = Mapper.Map<Source[], IEnumerable<Destination>>(sources); | |
| ICollection<Destination> icollectionDest = Mapper.Map<Source[], ICollection<Destination>>(sources); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE PROCEDURE usp_SelectRecord | |
| AS | |
| BEGIN | |
| SELECT * | |
| FROM TABLE | |
| END | |
| GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| routes.MapRoute( | |
| "Product", | |
| "Product/{productId}", | |
| new {controller="Product", action="Details"}, | |
| new {productId = @"\d+" } // matches only integers | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dbEnumIntValue = reader["EnumColumn"] as int? ?? 1; | |
| entity.EnumType = (EnumTypes)dbEnumIntValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static object GetDataValue(object value) | |
| { | |
| if (value == null) | |
| return DBNull.Value; | |
| return value; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while (reader.Read()) | |
| { | |
| // Use "as" instead of casting, if we are not using nullable types we can specify a default | |
| b.MediaType = reader["MediaType"] as Media.MediaTypes? ?? Media.MediaTypes.Photo; | |
| // no default needed here because our decimal is nullable | |
| b.Location.Latitude = reader["LocationLatitude"] as decimal?; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using(SqlConnection connection = new SqlConnection("connection string")) | |
| { | |
| connection.Open(); | |
| using(SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection)) | |
| { | |
| using (SqlDataReader reader = cmd.ExecuteReader()) | |
| { | |
| if (reader != null) | |
| { | |
| while (reader.Read()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| System.Configuration.ConfigurationManager.AppSettings["SettingName"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (reader["Column"] != System.DBNull.Value) | |
| returnVal = (string)reader["Column"]; | |
| else | |
| returnVal = string.Empty; |
NewerOlder