score:16

Accepted answer

I had the same problem some time ago and the solution for this was:

The entity framework was returning a serialized class instead of normal class. eg. Wallet_asfawfklnaewfklawlfkawlfjlwfejlkef instead of Wallet

To solve that you can add this code:

base.Configuration.ProxyCreationEnabled = false;

in your Context file. Since the context file is auto generated you can add it in the Context.tt In the Context.tt file it can be added around lines 55-65:

<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext
{
public <#=code.Escape(container)#>()
    : base("name=<#=container.Name#>")
{
base.Configuration.ProxyCreationEnabled = false;
<#
if (!loader.IsLazyLoadingEnabled(container))
{
#>
    this.Configuration.LazyLoadingEnabled = false;
<#

score:0

Are you trying to recieve a IEnumerable<Wallets>? If - yes, please modify your server class that returns the IEnumerable by adding .ToArray() method

score:1

Try specifying a setter for the properties, something like this :

[DataContract]
public partial class Wallet
{
    [DataMember]
    public int getwalletID { get { return walletID; } set { } }
    [DataMember]
    public string getname { get { return name; } set { } }
}

If it still doesn't work, you may consider creating an intermediate POCO class for this purpose, and use mapper library like AutoMapper or ValueInjecter to transfer the data from the EF objects.

The POCO class should have same properties as your EF class :

[DataContract]
public class WalletDTO
{
    [DataMember]
    public int walletID { get; set; }
    [DataMember]
    public string name { get; set; }
}

And modify your method to return this class instead :

public WalletDTO getWallet()
{
    Wallet w = new Wallet(); // or get it from db using EF

    var dto = new WalletDTO();        
    //assuming we are using ValueInjecter, this code below will transfer all matched properties from w to dto
    dto.InjectFrom(w); 
    return dto;
}

Related Articles