문제

OK, 나는 그냥 배우는 것을 꽤 확신합니다 ... 그러나 나는 매우 정규화 된 DB를 가지고 있습니다. 나는 제가 내 제품을 저장할 때 TBL을 저축 할 때도 있습니다....에 내 질문은 Silverlight에 있습니다. 이는 비동기입니다. 어떻게 다른 제품을 저장하는 것이 새 ID를 되돌리고 ProductDollar.ProductID FK 로 사용하는 방법은 어떻게 작동합니까?

지금까지 다른 저장소와 함께 Submitchanges의 콜백에서 제출을 사용합니다. 거기에서 나는 isCompleted를 확인하고 다음 저장을 위해 다음과 같은 ... 그런 것들을 함께 체인하십시오.

그러나 나는 500 개의 제품을 저장해야합니다 (한 번에 모두). 멋진 비치 엑스로 인해 제품 개체를 위조하는 것은 작동하지 않습니다. 그래서 나는 무엇을 그리워합니까 ???도움이나 포인터는 크게 감사 할 것입니다

도움이 되었습니까?

해결책

WCF RIA Services had this situation in mind when it was created. You can easily do it all in one SubmitChanges request and in one database transaction (depending on your DB and/or ORM). However, if you provide some more information about your objects (POCO, EF, etc.), you'll get a better answer.

That said, I'll take a wild guess at your objects as defined on the server.

public class Product
{
    [Key]
    public int? ProductID { get; set; }

    // ... more properties ...

    [Association("Product-ProductDollars", "ProductID", "ProductID", IsForeignKey = false)]
    [Include]
    [Composition]
    public ICollection<ProductDollar> ProductDollars { get; set; }
}

public class ProductDollar
{
    [Key]
    public int? ProductDollarID { get; set; }

    public int? ProductID { get; set; }

    // ... more properties ...

    [Association("Product-ProductDollars", "ProductID", "ProductID", IsForeignKey = true)]
    [Include]
    public Product Product { get; set; }
}

And your DomainService looks something like

public class ProductDomainService : DomainService
{
    public IQueryable<Product> GetProducts()
    {
        // Get data from the DB
    }

    public void InsertProduct(Product product)
    {
        // Insert the Product into the database

        // Depending on how your objects get in the DB, the ProductID will be set
        // and later returned to the client
    }

    public void InsertProductDollar(ProductDollar productDollar)
    {
        // Insert the ProductDollar in the DB
    }

    // Leaving out the Update and Delete methods
}

Now, on your client, you'll have code that creates and adds these entities.

var context = new ProductDomainContext();

var product = new Product();
context.Products.Add(product);

product.ProductDollars.Add(new ProductDollar());
product.ProductDollars.Add(new ProductDollar());

context.SubmitChanges();

This results in one request sent to the DomainService. However, WCF RIA splits this ChangeSet containing the 3 inserts into 3 calls to your DomainService methods:

  1. InsertProduct(Product product)
  2. InsertProductDollar(ProductDollar productDollar)
  3. InsertProductDollar(ProductDollar productDollar)

If your DomainService performs all inserts in one transaction, the ProductID can be correctly managed by your ORM.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top