New Posts New Posts RSS Feed: POCO And Master/Details
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

POCO And Master/Details

 Post Reply Post Reply
Author
antonio_sergio View Drop Down
Newbie
Newbie


Joined: 21-Oct-2010
Location: Braga
Posts: 9
Post Options Post Options   Quote antonio_sergio Quote  Post ReplyReply Direct Link To This Post Topic: POCO And Master/Details
    Posted: 03-Nov-2010 at 5:33am

Hello,
I have another problem. When I call a method (AllowRpc) and send an object of the type SalesOrderHeader as parameter the value of the EntityAspect is always null.

Regards,

Sérgio Magalhães

 

PS: I'm going crazy with Silverlight :(

Back to Top
jsobell View Drop Down
Groupie
Groupie
Avatar

Joined: 02-Apr-2009
Location: Australia
Posts: 80
Post Options Post Options   Quote jsobell Quote  Post ReplyReply Direct Link To This Post Posted: 28-Oct-2010 at 6:20pm
I'm just guessing here, but shouldn't your SalesOrderHeader initialise the empty collection itself, then you add the items to it, rather than creating an empty reference and assigning a destination collection?
I suppose it is nice if DF intercept the property set on a collection and automatically wrap all the child entities, but it seems to me to make more sense if POCO based entities followed the normal practice of adding items to an existing collection (which should perform tracking).
e.g.
var book = new AccountBook(); // This also initialises the Accounts and tracks additions/changes
book.Accounts.Add(new Account)

rather than

var book = new AccountBook(); // Accounts is null
book.Accounts = new List<Account>();
book.Accounts.Add(new Account)

I'm not sure if you would still have to EntityWrap the top AccountBook object, but it certainly sounds easier and more logical than wrapping every child object :)

Cheers,
 Jason
Back to Top
antonio_sergio View Drop Down
Newbie
Newbie


Joined: 21-Oct-2010
Location: Braga
Posts: 9
Post Options Post Options   Quote antonio_sergio Quote  Post ReplyReply Direct Link To This Post Posted: 28-Oct-2010 at 1:22am
Ok, thank for help Silvio.
 
Regards,
Sérgio Magalhães
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 27-Oct-2010 at 12:13pm
Hi Sergio,
 
I verified the behavior, and it looks like a bug. I am double checking with our senior engineer and will file a bug report.
 
In the meantime, you can workaround this issue by wrapping your SalesOrderDetail entities at runtime:
 
EntityWrapper.Wrap(aSalesOrderDetail);
 
Regards,
   Silvio.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 25-Oct-2010 at 4:47pm
Hi Sergio,
  I am looking at your example and will follow up soon.
 
Silvio.
Back to Top
antonio_sergio View Drop Down
Newbie
Newbie


Joined: 21-Oct-2010
Location: Braga
Posts: 9
Post Options Post Options   Quote antonio_sergio Quote  Post ReplyReply Direct Link To This Post Posted: 25-Oct-2010 at 10:53am
Good afternoon,

I was trying to create a sample project with a Master / Details and POCO's and am having a problem.

The property (EntityAspect) of my Detail is always with the null value.
What am I doing wrong?

Could you send me an example to work or see
what's going on with my example??
SalesOrderHeader:
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using IdeaBlade.EntityModel;

namespace SalesPoco
{
    [DataContract]
    public class SalesOrderHeader : IHasEntityAspectINotifyPropertyChanged
    {

        [Key]
        [DataMember]
        public int SalesOrderID
        {
            get { return _SalesOrderID; }
            set
            {
                _SalesOrderID = value;
                OnPropertyChanged("SalesOrderID");
            }
        }
        private int _SalesOrderID;


        [DataMember]
        public int CustomerID
        {
            get { return _CustomerID; }
            set
            {
                _CustomerID = value;
                OnPropertyChanged("CustomerID");
            }
        }
        private int _CustomerID;

        [DataMember]
        public decimal TotalDue
        {
            get { return _TotalDue; }
            set
            {
                _TotalDue = value;
                OnPropertyChanged("TotalDue");
            }
        }
        private decimal _TotalDue;

        [DataMember]
        public string Comment
        {
            get { return _Comment; }
            set
            {
                _Comment = value;
                OnPropertyChanged("Comment");
            }
        }
        private string _Comment;

        [DataMember]
        [Association("SalesOrderHeader_SalesOrderDetail""SalesOrderID""SalesOrderID")]
        public List<SalesOrderDetail> SalesOrderDetails
        {
            get { return _SalesOrderDetails; }
            set
            {
                _SalesOrderDetails = value;
                OnPropertyChanged("SalesOrderDetails");
            }
        }
        private List<SalesOrderDetail> _SalesOrderDetails;

        #region IHasEntityAspect Members

        public EntityAspect EntityAspect
        {
            get;
            set;
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string property)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(thisnew PropertyChangedEventArgs(property));
            }
        }

        #endregion
    }
}
 
SalesOrderDetail:

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using IdeaBlade.EntityModel;
namespace SalesPoco
{
    [DataContract]
    public class SalesOrderDetail : IHasEntityAspectINotifyPropertyChanged
    {
        [Key]
        [DataMember]
        public int SalesOrderID
        {
            get { return _SalesOrderID; }
            set
            {
                _SalesOrderID = value;
                OnPropertyChanged("SalesOrderID");
            }
        }
        private int _SalesOrderID;

        [Key]
        [DataMember]
        public int SalesOrderDetailID
        {
            get { return _SalesOrderDetailID; }
            set
            {
                _SalesOrderDetailID = value;
                OnPropertyChanged("SalesOrderDetailID");
            }
        }
        private int _SalesOrderDetailID;

        [DataMember]
        public short OrderQty
        {
            get { return _OrderQty; }
            set
            {
                _OrderQty = value;
                OnPropertyChanged("OrderQty");
            }
        }
        private short _OrderQty;

        [DataMember]
        public int ProductID
        {
            get { return _ProductID; }
            set
            {
                _ProductID = value;
                OnPropertyChanged("ProductID");
            }
        }
        private int _ProductID;

        [DataMember]
        public decimal UnitPrice
        {
            get { return _UnitPrice; }
            set
            {
                _UnitPrice = value;
                OnPropertyChanged("UnitPrice");
            }
        }
        private decimal _UnitPrice;



        #region IHasEntityAspect Members

        public EntityAspect EntityAspect
        {
            get;
            set;
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string property)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(thisnew PropertyChangedEventArgs(property));
            }
        }

        #endregion

    }
}
 
Server:

using System;
using System.Collections.Generic;
using IdeaBlade.Core.DomainServices;
namespace SalesPoco
{
    [EnableClientAccess]
    public class SalesPocoServiceProvider
    {
        public SalesPocoServiceProvider() { }

        public IEnumerable<SalesOrderHeader> GetSalesOrderHeader()
        {
            IEnumerable<SalesOrderHeader> states = ReadSalesOrderHeader();
            return states;
        }

        private IEnumerable<SalesOrderHeader> ReadSalesOrderHeader()
        {
            List<SalesOrderHeader> lstSalesOrderHeader = new List<SalesOrderHeader>();

            SalesOrderHeader orderHeader = new SalesOrderHeader();
            orderHeader.SalesOrderID = 1;
            orderHeader.CustomerID = 123;
            orderHeader.Comment = "Test";
            orderHeader.TotalDue = 12;
            orderHeader.SalesOrderDetails = ReadSalesOrderDetails(orderHeader.SalesOrderID);

            lstSalesOrderHeader.Add(orderHeader);

            return lstSalesOrderHeader;
        }

        private List<SalesOrderDetail> ReadSalesOrderDetails(int SalesOrderID)
        {
            List<SalesOrderDetail> listOrderDetail = new List<SalesOrderDetail>();
            for (int i = 0; i < 4; i++)
            {
                SalesOrderDetail orderDetail = new SalesOrderDetail();
                orderDetail.SalesOrderID = SalesOrderID;
                orderDetail.SalesOrderDetailID = i;
                orderDetail.ProductID = Convert.ToInt32("0011" + i.ToString());
                orderDetail.OrderQty = 1;
                orderDetail.UnitPrice = 10;
                listOrderDetail.Add(orderDetail);
            }
            return listOrderDetail;
        }

    }
}
 
Regards,

Sergio Magalhaes


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down