-
supporting state management for poco object in object context
var entry = context.ObjectStateManager.GetObjectStateEntry(poco);
For the Entity Framework to create the change-tracking proxies for your POCO classes, the following conditions must be met,
1. The class must be public, non-abstract, and non-sealed.
2. The class must implement virtual getters and setters for all properties that are
persisted.
3. You must declare collection-based relationships navigation properties as
ICollection<T>. They cannot be a concrete implementation or another interface
that derives from ICollection<T>.
-
Functional aspect of c#
Two generic delegate in c#, makes c# look more like a functional language, they are Action<T>, Func<T1, T2, ...>. The functional feature let you easily express your algorithm, without using the traditional design pattern. These delegates can be compared with function in javascript, and lamda in other language. For example,
interface IStrategy { void Execute(object o); }Using design pattern, we have to write a more code to aggregate different strategies. But using Action<T> is more succinct.
Action<object> oldAction = ... ;// Action<object> newAction = (o) => { Console.Write("preAction"); oldAction(o); Console.Write("postAction"); } newAction(o);If we want to go a step further, we can use function(lamda, delegate) to create functions. For example:
Func<Action<object>, Action<object>> createFunc = (func) => { return (o) => { Console.Write("preAction"); func(o); Console.Write("postAction"); }; } -
Return statement in javascript
return expression; //or return;
If there is no expression, then the return value is undefined. Except for constructor, whose return value is this
-
Throw error
//"throw" is not limited just throwing Error, basically, you can throw anything.
-
Array in javascript
Technically, array in javascript is not really array in the context of other language like c#, it is more like a dictionary, the index is actually used as a key of an entry in the dictionary, like to the following.
var a = []; a[0] = "fred"; alert(a["0"] == a[0]);
It is unique in that it has a length property, when you push an new item, array can automatically increase its length. It is also unique in that it support traditional for statement like for (i=1; i< a.length; i++) { ... }. Because Array is also an object so we can also use statement like "for ( var i in x), but it is not recommended because it defeat the purpose of array.
On the other hand, we can simulate the array feature for normal object. jQuery also use the technique like the following, so that jQuery object looks like an object, but it is not.
var push = [].push; var y = {}; push.call(y, 100); alert(y.length); //1 alert(y[0]); //100 To delete an array, do not use "delete array[index]" use array.splice(index, 1);