Random Dev Notes

August 19, 2009

LINQ to VFP – Example #1

Filed under: Development — Tags: — Tom Brothers @ 9:13 pm

The following example is a quick proof of concept simply showing how to view the Customer table from the Northwind.dbc.

  1. Create a new WebSite.
  2. Add references to IQToolkit.dll and LinqToVfp.dll
  3. Add a Northwind connection string setting to the web.config
    <connectionStrings>
      <add name="northwind"
           providerName="System.Data.OleDb"
           connectionString="Provider=VFPOLEDB.1;Data Source=**Your Path**Northwind.dbc;"/>
    </connectionStrings>
  4. Add a new class: Customer.cs
    public class Customer {
        public string CustomerId { get; set; }
        public string CompanyName { get; set; }
        public string ContactName { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
        public string Phone { get; set; }
        public string Fax { get; set; }
    }
  5. Add a new class: Northwind.cs
    using System.Configuration;
    using IQToolkit;
    using LinqToVfp;
    
    
    public class Northwind : AVfpDatabaseContainer {
        public Northwind()
            : base(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString, null) {
            // this will make it so that all command will be logged to the Output windoww
            this.Provider.Log = VfpQueryProvider.CreateDebuggerWriter();
        }
    
    
        public IEntityTable<Customer> Customers {
            get { return this.Provider.GetTable<Customer>("Customers"); }
        }
    }
  6. Modify Default.aspx to include to following in the div tag:
    <asp:GridView ID="mainGrid"
                  runat="server"
                  DataSourceID="LinqDataSource1"
                  AllowPaging="True"
                  AllowSorting="True" />
    
    
    <asp:LinqDataSource ID="LinqDataSource1"
                        runat="server"
                        ContextTypeName="Northwind"
                        TableName="Customers" />

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: