score:16
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;
}
Source: stackoverflow.com
Related Articles
- Return Entity Framework objects over WCF
- How to loop through a child list of objects in Entity Framework 4.1 code first
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Which LINQ statements force Entity Framework to return from the DB?
- Entity Framework 6 Code First Custom Functions
- return list with anonymous type in entity framework
- Do entity framework object references equal for same database objects
- Entity Framework Data Transfer Objects Best Practice
- Entity Framework Query - Get Objects in Specific Order
- Avoiding repeated projection code in Entity Framework
- How to prevent Entity Framework from loading all child objects
- Forcing Entity Framework to not generate NCLOB's when building Linq-to-Sql Code (Model First)
- How do I extend ADO.NET Entity Framework objects with partial classes?
- Entity Framework - Select specific columns and return strongly typed without losing cast
- Entity Framework Code First without app.config
- Is it possible to get Entity Framework to recognize objects that have been created and not yet saved in database?
- Return parent and children in single entity framework query WITHOUT returning IQueryable or IEnumerable?
- Entity framework - how to add complex objects to db
- Entity Framework - Using Navigation Properties over Joins
- Entity Framework Code First using context in Controller
- Entity Framework Core: Include many-to-many related objects in WebAPI
- Return record with max column value using Entity Framework 6
- many to many mapping in entity framework code first
- How to Create a Run-Time Computed (NotMapped) Value in Entity Framework Code First
- Entity Framework - Linq - Comparing Nullable objects - NotSupportedException
- updating data in many-to-many relationship in entity framework in code first existing database
- How can I return if an optional navigation property exists from an Entity Framework Query?
- Entity Framework Code First String Comparison with Oracle Db
- SQL subquery result in LINQ and Entity Framework Code First
- C# Entity Framework 4.1: include paths in query for loading related objects
- Linq extension method, how to find child in collection recursive
- ExpressionTree creation for y => ConstantCollection.Any(x => y.Contains(x)). Different scope parameterExpressions
- Manipulating array's index using Lambda Expression
- Filling class object from multiple dataset
- Distinct all columns in a datatable and store to another datatable with LINQ
- Entity Framework 5 Guid comparison results in no SQL being executed
- Good Fast Way to Let Users Visualize and Explore Relational Data?
- LINQ is it possible to add where clauses dynamically
- LINQ to entity Error: "Unable to create a null constant value of type ''System.Int32[]". Only entity types, enumeration types
- Finding bounds with LINQ
- How do I Take everything in a collection using Linq?
- LINQ Expression to Select objects by string property with maximum count of objects in its queue property without duplicates
- Beginner mistake in Linq Extension Methods with Entity Framework
- How can I create an Lambda Expression for Linq in the Where clause for two tables after the Join?
- Ambiguous call between within Mono for System.Linq.Enumerable.Max
- How to keep order by query result as in same order if it given to sub query?
- Find matched directories using a list of regular expressions
- selecting a set of objects based on index linq
- Help required to optimize LINQ query
- Using variables to build a LinQ query?