各製品の資料を入手。
詳細はこちら →CData
こんにちは!ウェブ担当の加藤です。マーケ関連のデータ分析や整備もやっています。
Entity Framework はobject-relational mapping フレームワークで、データをオブジェクトとして扱うために使われます。Visual Studio のADO.NET Entity Data Model ウィザードを実行するとEntity Model を作成できますが、このモデルファーストアプローチでは、データソースに変更があった場合やエンティティ操作をより制御したい場合は不都合があります。この記事では、CData ADO.NET Provider を使いコードファーストアプローチでSAP Netweaver Gateway にアクセスします。
SAP Gateway はBasic 認証とOAuth 2.0 認証の両方を許可します。Basic 認証を使用して自分のアカウントに接続するか、OAuth を使用して他のユーザーが彼らのアカウントでサービスからデータを取得できるようにすることができます。基本となる認証情報に加え、SAP Gateway テーブルへのアクセスには以下の追加プロパティが必要です。
Basic 認証では、自分のログインクレデンシャルを使用して接続します。次のプロパティを設定します。
ユーザー資格情報の接続プロパティを設定せずに接続できます。 接続すると、CData 製品はデフォルトブラウザでSAP Gateway OAuth エンドポイントを開きます。ログインして、CData 製品にアクセス許可を与えます。CData 製品が以下のOAuth プロセスを完了します。 他のOAuth 認証フローについては、ヘルプドキュメントの「OAuth 認証の使用」を参照してください。
<configuration>
... <connectionStrings>
<add name="SAPGatewayContext" connectionString="Offline=False;User=user;Password=password;URL=https://sapes5.sapdevcenter.com/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/;" providerName="System.Data.CData.SAPGateway" />
</connectionStrings>
<entityFramework>
<providers>
... <provider invariantName="System.Data.CData.SAPGateway" type="System.Data.CData.SAPGateway.SAPGatewayProviderServices, System.Data.CData.SAPGateway.Entities.EF6" />
</providers>
<entityFramework>
</configuration>
</code>
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
class SAPGatewayContext :DbContext {
public SAPGatewayContext() { }
protected override void OnModelCreating(DbModelBuilder modelBuilder) { // To remove the requests to the Migration History table
Database.SetInitializer<SAPGatewayContext>(null); // To remove the plural names modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations.Schema;
public class SalesOrderLineItems {
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.String Id { get; set; }
public System.String ProductID { get; set; }
}
public class SalesOrderLineItemsMap :EntityTypeConfiguration<SalesOrderLineItems> {
public SalesOrderLineItemsMap() {
this.ToTable("SalesOrderLineItems");
this.HasKey(SalesOrderLineItems => SalesOrderLineItems.Id);
this.Property(SalesOrderLineItems => SalesOrderLineItems.ProductID);
}
}
public DbSet<SalesOrderLineItems> SalesOrderLineItems { set; get; }
SAPGatewayContext context = new SAPGatewayContext();
context.Configuration.UseDatabaseNullSemantics = true;
var query = from line in context.SalesOrderLineItems select line;