• XAML is faster than code in silverlight

    Parsing XAML is faster than intantiating objects from code, because XAML parser does not create the API objects you use to interact with elements, but instead only create an internal representation. After you start interacting with elements from code, silverlight creates api objects that will slow down your application.

  • an another way to do setInterval

    In window object, there is a function setInterval which allows your to run a task repeatedly at an interval.


    setInterval(doSomething; 100);
    


    However, if the method last longer than the preset interval, it is not so efficient. We can use the follow function to make it more predictable.


    loopTask(doSomething, 100);
    
    
  • notes of regular expression in javascript

    The simplest way to tell whether a regular expression is find in source string is to use the "test" method.


    var reg = /a/;
    var found = reg.test("abc");
    console.log(found);
    


    In lots of occasion, we use regular expression to test user's input, for example to test if a input is in date format. You need the "^" and "$" character to wrap the regular expression pattern.


    To do a simple search in string, we can use string.match(regex) syntax. This is useful when we do want to whether a match or how many matchs can be found. If you just care about a first match, you will use non global regular expression. In this case, f a match is found, an array object will be return, the first element of the array is the entire match, the 1 to (length -1)th members of the array is the sub matches which are generated by the round bracket "()". The array or match object also has property "index" and "input". When a regular expression search is perform, the RegExp object also get updated.


    var src = "Please send mail to george@contoso.com and someone@example.com. Thanks!";
    
    
  • poco fix-up during relation change

    I have a poco entity like following. At first I do not have Items navigation property, but it turns out, this property is important. Bascially it makes the following code work.



    var countBeforeInsert = _db.Entities.Count();
                //
                Entity parent = new Entity();
                parent.Id = Guid.NewGuid();
                parent.Name = "parent";
                parent.Created = DateTime.Now;
                parent.LastUpdated = DateTime.Now;
    
    
  • Define entity from "view"

    When you have Entity that mapping to more than one table in a database. You probably have options to do the mapping.


    The first option is defined import all the tables into the StorageModels, but not ConceptualModels, define you entity without mapping, then manually edit the edmx file and to define the mapping. Because the entity mapping is manual, you need to define the CRUD manually. You can use store proc to do that.

    <EntitySetMapping Name="DummyExes">
                <QueryView>
                  select value EFTestModel.DummyEx(p.Id, p.c1, p.c2, c.c3)
                  from EFTestModelStoreContainer.Dummy as p
                  left join EFTestModelStoreContainer.DummyEx as c
                  on p.Id = c.DummyId
                </QueryView>
              </EntitySetMapping>
    

    The second option is defined a view in database, import that view and mapping to your entity. Because database view are normally treated readonly, you can define CRUD operation using stored proc, just like QueryView. Or you edit edmx file, cheat the ef runtime to think the view as talbe, then define insteadof trigger to do the update.