Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Tagged as

Go to top

Building an embedded database engine in C#

, 10 Jun 2009
DbfDotNet is a very fast and compact fully managed standalone database/entity framework, for the .Net Framework.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DbfDotNet.Linq
{
    using System.Linq;
    using System.Linq.Expressions;

    public class DbfTable<TRecord> : DbfDotNet.DbfTable<TRecord>, IQueryProvider, IQueryable<TRecord>
        where TRecord : DbfRecord, new()
    {
        private System.Linq.Expressions.Expression mExpression;

        public DbfTable(string filepath, System.Text.Encoding encoding, DbfVersion version)
            : base(filepath, encoding, version)
        {
            mExpression = Expression.Constant(this);
        }

        #region IQueryProvider Members

        IQueryable<TElement> IQueryProvider.CreateQuery<TElement>(System.Linq.Expressions.Expression expression)
        {
            if (typeof(TRecord) == typeof(TElement))
            {
                return (IQueryable<TElement>)new DbfQuery<TRecord>(this, expression);
            }
            throw new Exception("TElement should be TRecord");
        }

        IQueryable IQueryProvider.CreateQuery(System.Linq.Expressions.Expression expression)
        {
            return new DbfQuery<TRecord>(this, expression);
        }

        TResult IQueryProvider.Execute<TResult>(System.Linq.Expressions.Expression expression)
        {
            throw new NotImplementedException();
        }

        object IQueryProvider.Execute(System.Linq.Expressions.Expression expression)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<TRecord> Members

        IEnumerator<TRecord> IEnumerable<TRecord>.GetEnumerator()
        {
            for (UInt32 i = 0; i < RecordCount; i++)
            {
                TRecord r = this.GetRecord(i);
                yield return r;
            }
        }

        //private new TRecord GetRecord(int i)
        //{
        //    throw new NotImplementedException();
        //}

        //private new int RecordCount
        //{
        //    get{ return 0; } 
        //}

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            for (UInt32 i = 0; i < RecordCount; i++)
            {
                TRecord r = this.GetRecord(i);
                yield return r;
            }
        }

        #endregion

        #region IQueryable Members

        Type IQueryable.ElementType
        {
            get { throw new NotImplementedException(); }
        }

        System.Linq.Expressions.Expression IQueryable.Expression
        {
            get { return mExpression; }
        }

        IQueryProvider IQueryable.Provider
        {
            get { return this; }
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pascal Ganaye
Software Developer (Senior)
United Kingdom United Kingdom
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

| Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 10 Jun 2009
Article Copyright 2009 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid