Skip to content

Getting Started

Todd Thomson edited this page Aug 13, 2018 · 9 revisions

The DataContext

Your application must first create a custom data context by declaring a class that is derived from DataContext.

    /// <summary>
    /// The Todo app data context.
    /// </summary>
    /// <remarks>
    /// Custom data contexts derive from <see cref="DataContext"/>.
    /// </remarks>
    public class TodoDataContext: DataContext
    {
    }

EntitySets

Next, define and add your EntitySets to you DataContext.

    public class TodoDataContext: DataContext
    {
        private static TodoDataContext _dataContext;

        /// <summary>
        /// Gets or sets the Todo items.
        /// </summary>
        /// <remarks>
        /// Entity sets support the <see cref="IQueryable"/> interface.
        /// </remarks>
        public EntitySet<TodoItem> TodoItems { get; set; }

        public TodoDataContext( DataContextOptions options ) : base( options )
        {
            // Add your entity sets to the context in the data context constructor.
            TodoItems = new EntitySet<TodoItem>( this );
        }
    }