Question

i have a class library in c# and entity framework that has a payment model.

My payment model have one table called Payment, and then another table called PaymentSolid, this last one saves the solid values of the first one like if the first one have IdSeller, then the seccond one have SellerName.

My question is that i have a method called NewPayment where i create the Payment entity and the PaymentSolid. I have the next code in my method:

Payment ret;
        using (var context = new MyEntities())
        {
            ret = new Payment
            {
                id_buyer = IdBuyer,
                id_seller = IdSeller,
                id_seller_bill_to = IdSellerBillTo,
                id_payment_method = IdPaymentMethod,
                creation_date = CreationDate,
                payment_status = PaymentStatus,
                notes = Notes
            };
            context.Payments.AddObject(ret);
            context.Refresh(RefreshMode.StoreWins, ret);
            var retSolid = new PaymentSolid { 
                buyer_name = ret.Buyer.ProviderName,
                seller_name = ret.Seller.ProviderName,
                seller_bill_to_name = ret.SellerBillTo != null ? ret.SellerBillTo.ProviderName : null,
                payment_method_name = ret.PaymentMethod.name
            };
            ret.PaymentSolid = retSolid;
            context.SaveChanges();
            context.Refresh(RefreshMode.StoreWins, ret);
        }
        return ret;
    }

And my question is if i can use the ret.Buyer.ProviderName to create the solid or if i have to save the Payment first to then create the solid.

Was it helpful?

Solution

If you are using id_buyer to create the relationsip between Payment and Buyer you'll need to save ret first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top