سؤال

حسنا، أنا متأكد من أنه مجرد مسألة تعلم ... ولكن لدي DB طبيعي للغاية أنا أعمل مع ذلك عندما أحصل على المنتج الخاص بي TBL لدي أيضا productDollar Sttle وهكذا ..وبعد سؤالي في Silverlight كل شيء هو Async، فكيف يمكنني حفظ منتج استعادة معرفه الجديد واستخدام ذلك كمنتج ProductDollar.Productid FK

حتى الآن مع محفظاتي الأخرى، أنا فقط استخدم Submitoperation في رد السقوط وفي هناك، أتحقق من apcomppleted وقم بالحفظ التالي وهلم جرا ... وسلسلة منها معا مثل هذا.

ولكن لدي 500 منتج أحتاج إلى حفظ (كل ذلك مرة واحدة) لذا فإن القيام بتوقيف حول كائن المنتج لن يعمل بسبب ASYNC الرائع إذن ما الذي أفتقده ؟؟سيتم تقدير أي مساعدة أو مؤشرات بشكل كبير

هل كانت مفيدة؟

المحلول

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