イムを使用して、多くの関係に多くのEntity Frameworkの内のレコードを複製します。 私は2つのエンティティを持っています:多対多の関係を持つ製品とサプライヤ。は、エンティティフレームワークとasp.net定型を使用してAsp.net定型
私の問題:私は1社のまたは複数のサプライヤーと製品を保存すると、製品およびsupplierProductテーブル上の関係が保存されているが、供給業者記録は、サプライヤーテーブルの上に複製されます。
私は、異なるコンテキストからの2つの実体があるので、それが起こる読んで、私は製品のコンテキストにサプライヤーを「添付」が必要です。私はそれをする方法を知らない。誰かが私を助けることができますか?
マイエンティティ:
public class Product : FullAuditedEntity
{
public Product()
{
Suppliers = new HashSet<Supplier>();
}
public string Name { get; set; }
public virtual ICollection<Supplier> Suppliers { get; set; }
}
public class Supplier : FullAuditedEntity
{
public Supplier()
{
Products = new HashSet<Product>();
}
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
プロダクトマネージャーと呼ばれるマイドメインサービス
public async Task<Product> Create(Product entity)
{
var product = _repositoryProduct.FirstOrDefault(x => x.Id == entity.Id);
if (product != null)
{
throw new UserFriendlyException("Product already exists.");
}
else
{
return await _repositoryProduct.InsertAsync(entity);
}
}
ProductAppServiceと呼ばれる自分のアプリケーション・サービス:
public async Task Create(CreateProductInput input)
{
Product output = Mapper.Map<CreateProductInput, Product>(input);
await _productManager.Create(output);
}
マイCreateProductInputデータ転送オブジェクト
public class CreateProductInput
{
public string Name { get; set; }
public ICollection<Supplier> Suppliers { get; set; }
}
マイ角度成分の製品リスト成分
// GET Products
function getProducts() {
productService.listAll()
.then(function (result) {
vm.users = result.data;
});
}
getProducts();
// GET Suppliers
function getSuppliers() {
supplierService.listAll()
.then(function (result) {
vm.suppliers = result.data;
});
}
getSuppliers();
//Save the data
vm.save = function() {
abp.ui.setBusy();
productService.create(vm.product)
.then(function() {
abp.notify.info(App.localize('SavedSuccessfully'));
$uibModalInstance.close();
}).finally(function() {
abp.ui.clearBusy();
getProducts();
});
}
最も関連性の高いメソッド実装 - 'Product'リポジトリの' InsertAsync'は含まれていません。 –
asp.netの定型句のメソッドhttps://github.com/aspnetboilerplate/aspnetboilerplate –
デフォルトの汎用リポジトリの実装はまったく未知であり、関連データを持つエンティティでは機能しません。ほとんどの場合、カスタムリポジトリを実装する必要があります。 –