Eager loading lets you load all your needed entities at once. If you prefer to get all your entities to work on in one database call, then Eager loading is the way to go. It also lets you load multiple levels.
You have two options to load related entities, you can choose either strongly typed or st...
After turning Lazy loading off you can lazily load entities by explicitly calling Load method for entries. Reference is used to load single navigation properties, whereas Collection is used to get collections.
Company company = context.Companies.FirstOrDefault();
// Load founder
context.Entry(com...
The most common way is to apply the extension via Config. Example:
# File: mysite/_config/config.yml
Member:
extensions:
- MyMemberExtension
The extensions config variable is of type "array", so you can add multiple extensions like this:
# File: mysite/_config/config.yml
Mem...
TRACE and DEBUG log levels are there to be able to convey high detail about the operation of the given code at runtime. Setting the log level above these is usually recommended, however some care must be taken for these statements to not affect performance even when seemingly "turned off"....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
The first RewriteCond helps exclude the files. The second RewriteCond checks if there is already a trailing slash. If the case is so RewriteRule is not applied.
If you have any URL that s...
The ProcessBuilder class makes it easy to send a command through the command line. All it requires is a List of Strings that make up the commands to be entered. You simply call the start() method on your ProcessBuilder instance to execute the command.
If you have a program called Add.exe which take...
Laravel's events allows to implement the Observer pattern. This can be used to send a welcome email to a user whenever they register on your application.
New events and listeners can be generated using the artisan command line utility after registering the event and their particular listener in App...
Here's a way to show a GIF preloader while an AJAX call is executing.
We need to prepare our add and remove preloader functions:
function addPreloader() {
// if the preloader doesn't already exist, add one to the page
if(!document.querySelector('#preloader')) {
var preloaderHTML = '<...
Notice, this is only for angular-cli up to 1.0.0-beta.10 version !
Some libraries or plugins may not have typings. Without these, TypeScript can't type check them and therefore causes compilation errors. These libraries can still be used but differently than imported modules.
Include a scr...
Though the transaction class method is called on some ActiveRecord class, the objects within the transaction block need not all be instances of that class. This is because transactions are per-database connection, not per-model.
In this example a balance record is transactionally saved even though ...
A transaction acts on a single database connection. If you have multiple class-specific databases, the transaction will not protect interaction among them. One workaround is to begin a transaction on each class whose models you alter:
Student.transaction do
Course.transaction do
course.enro...
Both #save and #destroy come wrapped in a transaction that ensures that whatever you do in validations or callbacks will happen under its protected cover. So you can use validations to check for values that the transaction depends on or you can raise exceptions in the callbacks to rollback, includin...
User-defined functionals
Users can create their own functionals to varying degrees of complexity. The following examples are from Functionals by Hadley Wickham:
randomise <- function(f) f(runif(1e3))
lapply2 <- function(x, f, ...) {
out <- vector("list", length(x...
The number that follows the associativity information describes in what order the operators are applied. It must always be between 0 and 9 inclusive. This is commonly referred to as how tightly the operator binds. For example, consider the following fixity declarations (in base)
infixl 6 +
infixl ...
The following will prompt a user for input, and then store that input as a string (text) in a variable. The variable is then used to give a message to the user.
#!/usr/bin/env bash
echo "Who are you?"
read name
echo "Hello, $name."
The command read here reads one line of ...
In same cases different models could have same fields and same procedures in the product life cycle.
To handle these similarities without having code repetition inheritance could be used.
Instead of inheriting a whole class, mixin design pattern offers us to inherit (or some says include) some met...
When matching the path of a route, you can do it explicitly, matching only one path, like so:
get "/hello" do
return "Hello!"
end
You can also use a regular expression to match complex routes. Any route which matches the regular expression will run that code block. If m...
To print a test field (TestField) from a test feature class (TestFC) in a test file geodatabase (Test.gdb) located in a temporary folder (C:\Temp):
with arcpy.da.SearchCursor(r"C:\Temp\Test.gdb\TestFC",["TestField"]) as cursor:
for row in cursor:
print row[0]
void main()
{
import std.stdio : writeln;
int[] arr = [1, 3, 4];
int i = 0;
assert(arr.length > 0, "Array must contain at least one element");
do
{
arr[i++] *= 2;
} while (i < arr.length);
writeln(arr); // [2, 6, 8]
}