Principal End of One2One Map in EntityFramework

21-11-2014

##What does principal end of an association means?

In one-to-one relation one end must be principal and second end must be dependent. Principal end is the one which will be inserted first and which can exist without the dependent one. Dependent end is the one which must be inserted after the principal because it has foreign key to the principal.

##How to config in FluentAPI? Say we have one to one User and UserProfile entities, and the User is principal, UserProfile is dependant.

class User{
   UserProfile Profile { get;set; }
   //...
}

class UserProfile{
   User User{ get;set; }
   //...
}

Then the fluentAPI configuration will be:

modelBuilder.Entity<User>().HasRequired(u => u.Profile).WithRequiredPrincipal(p => p.User);

Written with StackEdit.

Read More »

The 'interesting' JavaScript Types

20-11-2014

typeof primitive types

Here lists the typeof results of primitive types:

var undefinedVariable;
var nullValue = null;
var anObject = new Object();
var func = function () { };

typeof ("string"); //result in "string"
typeof (1024); // number
typeof (true); // boolean
typeof (undefinedVariable); // undefined
typeof (anObject ); // object
typeof (undeclaredValue); // undefined
typeof (nullValue); // object
typeof (null) // object
typeof (func) // function
typeof (Object) // function

Things need to be highlighted are:

  • Both undefined and undeclared variable are of type undefined
  • Variable is null when assigned with null otherwise it will be undefined
  • Object is a function
  • null is an object, I guess it means a null object.

Read More »

Great JavaScript Interview Questions

20-11-2014

19 Great JavaScript Interview Questions

copied from here

Namespace

What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a function block?

A: This is an increasingly common practice, employed by many popular JavaScript libraries (jQuery, Node.js, etc.). This technique creates a closure around the entire contents of the file which, perhaps most importantly, creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries.

Another feature of this technique is to allow for an easily referenceable (presumably shorter) alias for a global variable. This is often used, for example, in jQuery plugins. jQuery allows you to disable the $ reference to the jQuery namespace, using jQuery.noConflict(). If this has been done, your code can still use $ employing this closure technique, as follows:

(function($) { /* jQuery plugin code referencing $ */ } )(jQuery);

Read More »

Get Website URLs via JavaScript

20-11-2014

Copied from here

There are several ways you can do this, but one way might be best for certain situations (e.g. within an iFrame).

Protocol + Domain + Page

document.URL
> "http://example.com/page1.html"

document.location.href
> "http://example.com/page1.html"

Protocol + Domain

document.location.origin
> "http://example.com"

Domain

document.location.host
> "example.com"

Page

document.location.pathname
> "/page1.html"

Written with StackEdit.

Read More »

Using CSS Properties to Create a Cool Button

20-10-2014

Using CSS properties alone, recreate this button:

enter image description here

This would be a great test of the candidate’s CSS3 skills. This button is loaded with that kind of stuff. Things I would look for:

  • How did they handle multiple borders? box-shadow is probably the best way here.
  • Did they use text-transform: uppercase; for the text? That would be best.
  • How did they handle the stars? Pseudo elements would be a good candidate there. Did they use unicode? Icon font?
  • Did they catch the subtle text-shadow?
  • How did they split the background in the main part of the button? a linear-gradient with no fade would be a good technique there. Or box-shadow.
  • Were they careful with the nested border-radius?

My solution

a {
  border-radius: 4px;
  border-color : aliceblue;
  background-color: gray;
  padding: 5px;  
  display:inline;
  text-decoration: none;
  text-transform:uppercase;
  box-shadow:0px 0px 1px 4px red,
    0px 0px 1px 8px #000000;
  text-shadow:1px 1px #00ffff;
  font-weight: bold;
  background: linear-gradient(180deg, lightgray, gray);
}

a:before, a:after{
  content:'\2605';
}

The challenge/question was from here

Written with StackEdit.

Read More »