This example creates a Data Context class that creates a Customer property that can be used for querying. This example also shows how XML Mapping can be used to allow the entity class property names to be different from the table field names.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using IQToolkit;
using LinqToVfp;

namespace LinqToVfpQuickStart {
    static class Program {
        [STAThread]
        static void Main() {
            string northwindDbcPath = "your path";
            string connectionString = string.Format("Provider=VFPOLEDB.1;Data Source={0};Exclusive=false;Ansi=true;", northwindDbcPath);

            Northwind northwind = new Northwind(connectionString);

            List<Customer> customers = (from customer in northwind.Customers
                                        orderby customer.Name
                                        select customer).ToList();
        }
    }

    // Data Context Class
    public class Northwind {
        private VfpQueryProvider provider;

        public Northwind(string connectionString) {
            this.provider = VfpQueryProvider.Create(connectionString, null);
            this.provider = this.provider.New(VfpXmlMapping.FromXml(File.ReadAllText("Mapping.xml")));
        }

        public virtual IEntityTable<Customer> Customers {
            get { return this.provider.GetTable<Customer>("Customer"); }
        }
    }

    // Entity Class
    public class Customer {
        public string Id { get; set; }
        public string Name { get; set; }
    }
}

Mapping.xml
<?xml version="1.0" encoding="utf-8" ?>
<map>
	<Entity Id="Customer">
		<Table Name="Customers"/>
		<Column Member="Name" Name="companyname" />
		<Column Member="Id" Name="customerid" />
	</Entity>
</map>

Last edited Apr 17, 2010 at 3:13 PM by TomBrothers, version 1

Comments

No comments yet.