製品をチェック

無償トライアル:

無償トライアルへ

製品の情報と無償トライアルへ:

FinancialForce ADO.NET Provider

FinancialForce データに連携する.NET アプリケーションを素早く、簡単に開発できる便利なドライバー。

データ連携でお困りですか?

お問い合わせ

Entity Framework 6 からFinancialForce データに連携


この記事は、Entity Framework のcode-first アプローチを使って、FinancialForce に接続する方法を説明します。Entity Framework 6 は.NET 4.5 以上で利用可能です。


financialforce ロゴ画像
ado ロゴ画像

ADO.NET

Entity Framework ロゴ画像


Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでFinancialForce にアクセスします。

  1. Visual Studio を起動し、新しいWindows Form アプリケーションを作成します。ここでは、.NET 4.5 のC# プロジェクトを使います。
  2. Visual Studio の [パッケージ マネージャー コンソール]から'Install-Package EntityFramework' コマンドを実行し、最新のEntity Framework をインストールします。
  3. プロジェクトのApp.config ファイルを修正して、FinancialForce Entity Framework 6 アセンブリおよびコネクションストリングへの参照を追加します。

    There are several authentication methods available for connecting to FinancialForce: login credentials, SSO, and OAuth.

    Authenticating with a Login and Token

    Set the User and Password to your login credentials. Additionally, set the SecurityToken. By default, the SecurityToken is required, but you can make it optional by allowing a range of trusted IP addresses.

    To disable the security token:

    1. Log in to FinancialForce and enter "Network Access" in the Quick Find box in the setup section.
    2. Add your IP address to the list of trusted IP addresses.

    To obtain the security token:

    1. Open the personal information page on FinancialForce.com.
    2. Click the link to reset your security token. The token will be emailed to you.
    3. Specify the security token in the SecurityToken connection property or append it to the Password.

    Authenticating with OAuth

    If you do not have access to the user name and password or do not want to require them, use the OAuth user consent flow. See the OAuth section in the Help for an authentication guide.

    Connecting to FinancialForce Sandbox Accounts

    Set UseSandbox to true (false by default) to use a FinancialForce sandbox account. Ensure that you specify a sandbox user name in User.

    <configuration> ... <connectionStrings> <add name="FinancialForceContext" connectionString="Offline=False;User=myUser;Password=myPassword;Security Token=myToken;" providerName="System.Data.CData.FinancialForce" /> </connectionStrings> <entityFramework> <providers> ... <provider invariantName="System.Data.CData.FinancialForce" type="System.Data.CData.FinancialForce.FinancialForceProviderServices, System.Data.CData.FinancialForce.Entities.EF6" /> </providers> <entityFramework> </configuration> </code>
  4. インストールディレクトリの[lib] > 4.0 サブフォルダにあるSystem.Data.CData.FinancialForce.Entities.EF6.dll を設定し、プロジェクトを作成してEntity Framework 6 を使うためのセットアップを完了します。
  5. この時点でプロジェクトを作成し、すべてが正しく動作していることを確認してください。これで、Entity Framework を使ってコーディングを開始できます。
  6. プロジェクトに新しい.cs ファイルを追加し、そこにクラスを追加します。これがデータベースのコンテキストとなり、DbContext クラスを拡張します。この例では、クラス名はFinancialForceContext です。以下のサンプルコードは、OnModelCreating メソッドをオーバーライドして次の変更を加えます:
    • PluralizingTableNameConvention をModelBuilder Conventions から削除。
    • MigrationHistory テーブルへのリクエストを削除。
    using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.Entity.ModelConfiguration.Conventions; class FinancialForceContext :DbContext { public FinancialForceContext() { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table Database.SetInitializer<FinancialForceContext>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); } }
  7. もう一つ.cs ファイルを作成し、ファイル名を呼び出そうとしているFinancialForce のエンティティ、例えばAccount にします。このファイルでは、エンティティとエンティティ設定の両方を定義します。以下に例を示します。 using System.Data.Entity.ModelConfiguration; using System.ComponentModel.DataAnnotations.Schema; public class Account { [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public System.String Id { get; set; } public System.String BillingState { get; set; } } public class AccountMap :EntityTypeConfiguration<Account> { public AccountMap() { this.ToTable("Account"); this.HasKey(Account => Account.Id); this.Property(Account => Account.BillingState); } }
  8. エンティティの作成が済んだので、コンテキストクラスにエンティティを追加します: public DbSet<Account> Account { set; get; }
  9. コンテキストとエンティティの作成が完了したら、別クラスでデータをクエリできます。例: FinancialForceContext context = new FinancialForceContext(); context.Configuration.UseDatabaseNullSemantics = true; var query = from line in context.Account select line;