本記事では CData サポート担当からこんなことを聞かれたらどこを確認すべきか?という観点で、よく頂くお問合せ内容をご紹介します。
記事はこちら →Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでPhoenix にアクセスします。
Phoenix Query Server 経由でApache Phoenix に接続します。デフォルトのポートと異なる場合は、Server とPort プロパティを設定してApache Phoenix に接続します。Servre プロパティは通常、Apache Phoenix をホストしているサーバーのホスト名またはIP アドレスです。
デフォルトでは、認証は使用されません(プレーン)。サーバーに認証が設定されている場合は、AuthScheme をNEGOTIATE に設定して、
必要な場合にはUser とPassword プロパティを設定して、Kerberos で認証します。
<configuration>
... <connectionStrings>
<add name="ApachePhoenixContext" connectionString="Offline=False;Server=localhost;Port=8765;" providerName="System.Data.CData.ApachePhoenix" />
</connectionStrings>
<entityFramework>
<providers>
... <provider invariantName="System.Data.CData.ApachePhoenix" type="System.Data.CData.ApachePhoenix.ApachePhoenixProviderServices, System.Data.CData.ApachePhoenix.Entities.EF6" />
</providers>
<entityFramework>
</configuration>
</code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class ApachePhoenixContext :DbContext {
public ApachePhoenixContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table
Database.SetInitializer<ApachePhoenixContext>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
public class MyTable {
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.String Id { get; set; }
public System.String Id { get; set; }
}
public class MyTableMap :EntityTypeConfiguration<MyTable> {
public MyTableMap() {
this.ToTable("MyTable");
this.HasKey(MyTable => MyTable.Id);
this.Property(MyTable => MyTable.Id);
}
}
public DbSet<MyTable> MyTable { set; get; }
ApachePhoenixContext context = new ApachePhoenixContext();
context.Configuration.UseDatabaseNullSemantics = true;
var query = from line in context.MyTable select line;