• change in mvc2 project

    1. project file change, replace guid {603c0e0b-db56-11dc-be95-000d561079b0} with {F85E285D-A4E0-4152-9332-AB1D724D3325} in ProejctTypeGuids nodes
    2. Reference dll change, update all reference in web.config files and project files update runtime binding.
      <runtime>  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">    <dependentAssembly>      
      <assemblyIdentity name="System.Web.Mvc"           publicKeyToken="31bf3856ad364e35"/>      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>    </dependentAssembly>  </assemblyBinding></runtime>
      
    3. javascript file changes, copy new script from new project to old project
  • Covariant/Contravariant Support for generic interface .net 4.0

    The introduction of generic in .net makes covariant/contravariant support a very interesting topic. Now .net 4, there are some support for generic interface. But covariant and contravariant for generic class is still not supported with good reason, so you can not write the following code in .net 2 and .net 4

    [TestMethod]
    public void no_covariant_support_for_generic_class()
    {
        //can not be compiled
        List<object> list = GetListOfString();
        //if support, what if use write
        list[0] = 1; //this is not secure
    
    
  • compiled time support for Covariant and Contravariant in .net 2.0


    In .net 2.0, A delegate can be associated with a named method, this facility provide support for covariant and contravariant as the following sample code shows.

            delegate void ProcessString(string item);
            delegate object GetObject();
    
    
  • The semantics of c# interface

    We all use interface construct in c#. Recently I came across the Haack’s blog Interface Inheritance Esoterica, I decided to find out more. So I write a very simple example like below

    public interface IAnimal
        {
            void Walk();
        }
    
    
  • Get started with EntityFramework 4

    We have the following option to using EntityFramework4


    • Using designer
      • Model First

        We can design model first , then generate the sql for the model, use the sql to generate the database, and then connect the model to the database. The process of sql gereration is customizable. You change this workflow (process) and the template of the sql, these file are located at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen.
        ASO.NET team blog has an article about this a approach.

      • Database First

        This is a classic approach. You have your database in the first place, and generate model based on that.


      Since you have use the designer, you have other customization options that are related to code generation from the model created by designer. But default designer use a Code generation strategy call "Default". If you model file name is "model.edmx", the strategy generate a cs file "model.cs" file, and the code generate the ObjectContext, and other entities, and so forth. The entities


      [EdmEntityTypeAttribute(NamespaceName="CrmModel", Name="Post")]
      [Serializable()]
      [DataContractAttribute(IsReference=true)]
      public partial class Post : EntityObject
      { ... }
      

      Since EF4 use t4 to generate code, you can customized the t4 to customized the code generation by right clicking the designer and adding code generation item. When you add code generation item, this will turn off the default code generation strategy. Your model.cs file will be empty.


      There are a couple code generation item available now. When you add an item a t4 file (*.tt) is added to the project. You can customize the tt file as want.


    • Use code only
      Feature CTP Walkthrough: Code Only for the Entity Framework (Updated)