ノーコードでクラウド上のデータとの連携を実現。
詳細はこちら →Certinia Data Provider の30日間無償トライアルをダウンロード
30日間の無償トライアルへCData
こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。
Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでCertinia にアクセスします。
デフォルトでは、CData 製品は本番環境に接続します。サンドボックスアカウントを使用するには、UseSandbox をtrue に設定します。User にサンドボックスのユーザー名を指定してください。
Certinia への接続に使用できる認証方法は以下のとおりです。
User およびPassword をログインクレデンシャルに設定します。さらにSecurityToken を設定します。SecurityToken については、信頼できるIP アドレスに利用中のIP を追加することで指定する必要がなくなります。
セキュリティトークンを無効にするには、以下の手順を実行してください。
セキュリティトークンの取得には、以下を実行してください。
すべてのOAuth フローで、AuthScheme をOAuth に設定する必要があります。詳しい設定方法については、ヘルプドキュメントの「OAuth」セクションを参照してください。
<configuration>
... <connectionStrings>
<add name="CertiniaContext" connectionString="Offline=False;User=myUser;Password=myPassword;Security Token=myToken;" providerName="System.Data.CData.Certinia" />
</connectionStrings>
<entityFramework>
<providers>
... <provider invariantName="System.Data.CData.Certinia" type="System.Data.CData.Certinia.CertiniaProviderServices, System.Data.CData.Certinia.Entities.EF6" />
</providers>
<entityFramework>
</configuration>
</code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class CertiniaContext :DbContext {
public CertiniaContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table
Database.SetInitializer<CertiniaContext>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
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);
}
}
public DbSet<Account> Account { set; get; }
CertiniaContext context = new CertiniaContext();
context.Configuration.UseDatabaseNullSemantics = true;
var query = from line in context.Account select line;