This file contains 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 System.Data.Entity; | |
// In Entity Framework, an enumeration can have the following underlying types: Byte, Int16, Int32, Int64 , or SByte. | |
public enum DepartmentNames | |
{ | |
English, | |
Math, | |
Economics | |
} |
This file contains 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
// The SqlQuery method on DbSet allows a raw SQL query to be written that will return entity instances. The returned objects // will be tracked by the context just as they would be if they were returned by a LINQ query. For example: | |
using (var context = new BloggingContext()) | |
{ | |
var blogs = context.Blogs.SqlQuery("SELECT * FROM dbo.Blogs").ToList(); | |
} | |
/* | |
Note that, just as for LINQ queries, the query is not executed until the results are enumerated—in the example above this is done with the call to ToList. | |
Care should be taken whenever raw SQL queries are written for two reasons. First, the query should be written to ensure that it only returns entities that are really of the requested type. For example, when using features such as inheritance it is easy to write a query that will create entities that are of the wrong CLR type. |
This file contains 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 the Model | |
/* | |
For simplicity’s sake, we’ll begin by setting-up a C# console application for managing a database of questions and answers, called “AnswersDB.” Each question can have multiple answers, and each answer belongs to only one question. We’ll be using EF’s Code First workflow to create our model and generate the database. | |
Here is the model that powers this Q&A service: | |
*/ | |
public class Question | |
{ |
This file contains 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
/* | |
Unit tests for a ASP.NET Web API controller in the EFMVC reference application. Let me introduce the EFMVC app, If you haven't heard about EFMVC. EFMVC is a simple app, developed as a reference implementation for demonstrating ASP.NET MVC, EF Code First, ASP.NET Web API, Domain-Driven Design (DDD), Test-Driven Development (DDD). The current version is built with ASP.NET MVC 4, EF Code First 5, ASP.NET Web API, Autofac, AutoMapper, Nunit and Moq. All unit tests were written with Nunit and Moq. You can download the latest version of the reference app from http://efmvc.codeplex.com/ | |
*/ | |
// Unit Test for HTTP Get | |
/* | |
Let’s write a unit test class for verifying the behaviour of a ASP.NET Web API controller named CategoryController. Let’s define mock implementation for Repository class, and a Command Bus that is used for executing write operations. | |
*/ |
This file contains 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
Introduction | |
The code first fluent API is most commonly accessed by overriding the OnModelCreating method on your derived DbContext. The following samples are designed to show how to do various tasks with the fluent api and allow you to copy the code out and customize it to suit your model, if you wish to see the model that they can be used with as-is then it is provided at the end of this article. | |
Property Mapping | |
The Property method is used to configure attributes for each property belonging to an entity or complex type. The Property method is used to obtain a configuration object for a given property. The options on the configuration object are specific to the type being configured; IsUnicode is available only on string properties for example. |
This file contains 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
Type Discovery | |
When using Code First development you usually begin by writing .NET Framework classes that define your conceptual (domain) model. In addition to defining the classes, you also need to let DbContext know which types you want to include in the model. To do this, you define a context class that derives from DbContext and exposes DbSet properties for the types that you want to be part of the model. Code First will include these types and also will pull in any referenced types, even if the referenced types are defined in a different assembly. | |
If your types participate in an inheritance hierarchy, it is enough to define a DbSet property for the base class, and the derived types will be automatically included, if they are in the same assembly as the base class. | |
In the following example, there is only one DbSet property defined on the SchoolEntities class (Departments). Code First uses this property to discover and pull in any referenced types. | |
public class SchoolEntities : DbContext | |
{ |
This file contains 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
// Node.js CheatSheet. | |
// Download the Node.js source code or a pre-built installer for your platform, and start developing today. | |
// Download: http://nodejs.org/download/ | |
// More: http://nodejs.org/api/all.html | |
// 0. Synopsis. | |
// http://nodejs.org/api/synopsis.html |
This file contains 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
## SYNTAX: | |
var pattern = new RegExp(pattern, attributes); # attributes: g (global); i (case-sensitive); m (multiline matches) | |
var pattern = /pattern/attributes; # same as above | |
## BRACKETS: | |
[...]: Any one character between the brackets. | |
[^...]: Any one character not between the brackets. |
This file contains 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
// Date Object CheatSheet | |
// The Date object is used to work with dates and times. | |
// More: http://www.w3schools.com/jsref/jsref_obj_date.asp | |
// 1. Instantiating a Date. | |
var date = new Date(); | |
var date = new Date(milliseconds); |
This file contains 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
# Node-WebKit CheatSheet | |
# Download: https://github.com/rogerwang/node-webkit#downloads | |
# Old Versions: https://github.com/rogerwang/node-webkit/wiki/Downloads-of-old-versions | |
# Wiki: https://github.com/rogerwang/node-webkit/wiki | |
# How: https://github.com/rogerwang/node-webkit/wiki/How-node.js-is-integrated-with-chromium | |
# 1. Run your application. | |
# https://github.com/rogerwang/node-webkit/wiki/How-to-run-apps |
OlderNewer