views:

22

answers:

2

hi all, i have a problem regarding data contract in my application. i have 5 tables in my database and i required 3 of them as datatype. so i created a class and decleared all required table as class under [datacontract] here's the code

[DataContract] public class CustomerDetail { [DataMember] public int CustomerID { get; set; } [DataMember] public string CustomerName { get; set; } [DataMember] public long ContactNumber { get; set; } [DataMember] public string Email { get; set; } [DataMember] public string Address { get; set; } [DataMember] public string Password { get; set; } }

[DataContract(Name = "CustomerDetail")]
public class CustomerAccount
{
    [DataMember]
    public int AccountId { get; set; }
    [DataMember ]
    public short PinNo { get; set; }
    [DataMember (Name="CustomerID")]
    public int CustomerID { get; set; }
    [DataMember]
    public int AccountTypeId { get; set; }
    [DataMember]
    public float Amount { get; set; }

}

[DataContract(Name = "CustomerDetail")]
public class TransactionDetail
{
    [DataMember]
    public int TransactionId { get; set; }
    [DataMember (Name ="CustomerID")]
    public int CustomerId { get; set; }
    [DataMember]
    public int AccountId { get; set; }
    [DataMember]
    public int TransactiopnTypeId { get; set; }
    [DataMember]
    public float AmountAfterTransaction { get; set; }
}

i hv used attributes too, but i am getting invalid data contract exception.. plz help me out what i should to solve this.

+1  A: 

I think it's because you're using the Name parameter in your Data Contracts. You seem to have cut and pasted these attributes.

Just remove all of the "Name" parameters from your DataContract and DataMember attributes. They aren't necessary for what you are doing and are causing you problems.

Dave Markle
I tryed it without any attribute but the same exception occured.Then I googled it but not got appropriate way to solve it.
+1  A: 

The problem is that you are using the same name "CustomerDetails" for mulitple objects. Try using this code in place of your code (Note: I just removed the two Name=CustomerDetail attributes).

 [DataContract]
    public class CustomerDetail
    {
        [DataMember]
        public int CustomerID { get; set; }
        [DataMember]
        public string CustomerName { get; set; }
        [DataMember]
        public long ContactNumber { get; set; }
        [DataMember]
        public string Email { get; set; }
        [DataMember]
        public string Address { get; set; }
        [DataMember]
        public string Password { get; set; }

    }
    [DataContract]
    public class CustomerAccount
    {
        [DataMember]
        public int AccountId { get; set; }
        [DataMember]
        public short PinNo { get; set; }
        [DataMember(Name = "CustomerID")]
        public int CustomerID { get; set; }
        [DataMember]
        public int AccountTypeId { get; set; }
        [DataMember]
        public float Amount { get; set; }

    }

    [DataContract]
    public class TransactionDetail
    {
        [DataMember]
        public int TransactionId { get; set; }
        [DataMember(Name = "CustomerID")]
        public int CustomerId { get; set; }
        [DataMember]
        public int AccountId { get; set; }
        [DataMember]
        public int TransactiopnTypeId { get; set; }
        [DataMember]
        public float AmountAfterTransaction { get; set; }
    } 
CkH