Up Code First
DevForce Resource Center » Development guide » Model » Code First » Code First code snippets

Code First code snippets

Last modified on September 14, 2012 18:30

Visual Studio code snippets for DevForce 2012 "Code First" can speed development of your entity models, reducing tedium and errors.

Snippets

There are five code snippets:

cflistnavprop.snippet, shortcut "cfnav",  emits a "list navigation" property returning a DevForce RelatedEntityList of entities. For example, a Customer entity might have an "Orders" list navigation property returning the customer's Orders. 

cfrefnavprop.snippet, shortcut "cfref", emits a "reference navigation" property and a companion foreign key property. The navigation property returns a single entity. For example a "Customer" property that returns the parent Customer entity. A reference navigation property usually has a corresponding foreign key property; a "Customer" property of an Order probably should have a foreign key property named CustomerId.

cfentitymanager.snippet, shortcut "cfentitymanager",  emits a custom EntityManager for your model. It consists mostly of standard constructors and the prototype of a query method. It produces a lot of inescapable boiler plate code that you'll probably need only once per application model.

cfentityqueryprop.snippet, shortcut "cfeq",  emits an EntityQuery<T> property for a custom EntityManager. For example, to add a Customers query property, use this snippet to add "public EntityQuery<Customer> Customers {get; set;}" to your EntityManager.

cfdbsetproperty.snippet, shortcut "cfdbset",  emits a DbSet<T> property for a custom DbContext. For example, to expose Customer entities, use this snippet to add "public DbSet<Customer> Customers {get; set;}" to your DbContext

Install

Download the code snippets

Unzip and find the snippets for your preferred language.

Copy the snippet files to a location where Visual Studio can find them such as:
"%USERPROFILE%\Documents\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets" or
"%USERPROFILE%\Documents\Visual Studio 2012\Code Snippets\Visual Basic\My Code Snippets".

Use in your code

Microsoft describes numerous ways to use a code snippet. We prefer the "short-cut" technique:

  1. Put the cursor where you want to insert the code snippet.
  2. Type the shortcut for the code snippet (e.g. "cfrefnavprop").
  3. Press TAB, TAB to invoke the code snippet.

Tags: code first
Created by DevForce on August 06, 2011 14:59

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade