Wednesday 27 June 2012

Using Entity Framework to create or update database(Migration)

Once you define your object model in C# or VB, you can push the object to your database. Most of the case entity framework will handle the update automatically. And you dont even need to write a SQL code.
This development method also commonly know as "Code First" in Entity Framework.

However I searched numbers of blog posts and found not a lot of them mention the command to generate and update database. And here are the procedures to create or update your databases:

  1. Develop your object in visual studio
  2. Make sure your connection is correct and the account have permission to crate and update
  3. Open package manager console (view > other windows >  package manager console)
  4. Enable automatic migration if you haven't by "PM> Enable-Migrations -EnableAutomaticMigrations"
  5. Update database command "PM> Update-Database"
Thanks Travis in providing these procedure.

Thursday 7 June 2012

Update status in CRM 2011

Here is the code to update a recode via CRM context object:

CRMContext.Execute(new SetStateRequest
            {
                EntityMoniker = new EntityReference
                {
                    Id = new Guid(""),
                    LogicalName = "" //Entity Name
                },
                State = new OptionSetValue(1), //get the value
                Status = new OptionSetValue(1)
            }
            );