本記事では CData サポート担当からこんなことを聞かれたらどこを確認すべきか?という観点で、よく頂くお問合せ内容をご紹介します。
記事はこちら →Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでSage 300 にアクセスします。
Sage 300 には、Sage 300 Web API で通信するための初期設定が必要となるます。
Basic 認証を使用してSage 300 へ認証します。
Sage 300 に認証するには、次のプロパティを入力してください。プロバイダーは、クッキーを使用してSage 300 が開いたセッションを再利用することに注意してください。 そのため、資格情報はセッションを開く最初のリクエストでのみ使用されます。その後は、Sage 300 が返すクッキーを認証に使用します。
<configuration>
... <connectionStrings>
<add name="Sage300Context" connectionString="Offline=False;User=SAMPLE;Password=password;URL=http://127.0.0.1/Sage300WebApi/v1/-/;Company=SAMINC;" providerName="System.Data.CData.Sage300" />
</connectionStrings>
<entityFramework>
<providers>
... <provider invariantName="System.Data.CData.Sage300" type="System.Data.CData.Sage300.Sage300ProviderServices, System.Data.CData.Sage300.Entities.EF6" />
</providers>
<entityFramework>
</configuration>
</code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class Sage300Context :DbContext {
public Sage300Context() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table
Database.SetInitializer<Sage300Context>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
public class OEInvoices {
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.String Id { get; set; }
public System.String InvoiceUniquifier { get; set; }
}
public class OEInvoicesMap :EntityTypeConfiguration<OEInvoices> {
public OEInvoicesMap() {
this.ToTable("OEInvoices");
this.HasKey(OEInvoices => OEInvoices.Id);
this.Property(OEInvoices => OEInvoices.InvoiceUniquifier);
}
}
public DbSet<OEInvoices> OEInvoices { set; get; }
Sage300Context context = new Sage300Context();
context.Configuration.UseDatabaseNullSemantics = true;
var query = from line in context.OEInvoices select line;