ノーコードでクラウド上のデータとの連携を実現。
詳細はこちら →無償トライアル:
無償トライアルへ製品の情報と無償トライアルへ:
Facebook Ads データに連携する.NET アプリケーションを素早く、簡単に開発できる便利なドライバー。
加藤龍彦
ウェブデベロッパー
ADO.NET Adapter
Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでFacebook Ads にアクセスします。
Most tables require user authentication as well as application authentication. Facebook uses the OAuth authentication standard. To authenticate to Facebook, you can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL or you can obtain your own by registering an app with Facebook.
See the Getting Started chapter of the help documentation for a guide to using OAuth.
<configuration>
... <connectionStrings>
<add name="FacebookAdsContext" connectionString="Offline=False;" providerName="System.Data.CData.FacebookAds" />
</connectionStrings>
<entityFramework>
<providers>
... <provider invariantName="System.Data.CData.FacebookAds" type="System.Data.CData.FacebookAds.FacebookAdsProviderServices, System.Data.CData.FacebookAds.Entities.EF6" />
</providers>
<entityFramework>
</configuration>
</code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class FacebookAdsContext :DbContext {
public FacebookAdsContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table
Database.SetInitializer<FacebookAdsContext>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
public class AdAccounts {
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.String Id { get; set; }
public System.String AccountId { get; set; }
}
public class AdAccountsMap :EntityTypeConfiguration<AdAccounts> {
public AdAccountsMap() {
this.ToTable("AdAccounts");
this.HasKey(AdAccounts => AdAccounts.Id);
this.Property(AdAccounts => AdAccounts.AccountId);
}
}
public DbSet<AdAccounts> AdAccounts { set; get; }
FacebookAdsContext context = new FacebookAdsContext();
context.Configuration.UseDatabaseNullSemantics = true;
var query = from line in context.AdAccounts select line;