

Unable to retrieve a single entity
source link: https://www.codesd.com/item/unable-to-retrieve-a-single-entity.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Unable to retrieve a single entity
I'm trying to retrieve a single entity by its ID in the DomainService
.
However the type of that entity is not generated in the client. Here is my query:
public Contact GetContact(int contactId)
{
return DbContext.Contacts
.Include(c => c.Phones)
.Include(c => c.Addresses)
.SingleOrDefault(c => c.ContactId == contactId);
}
The Phone
entity isn't generated on the client.
I tried decorating this method with [Query]
, but then I get the following compile-time exception:
Query operation 'GetContact' cannot be marked composable since its return type 'Models.Contact' does not implement IEnumerable of T.
Is there any way to create a WCF RIA query that returns a single entity by ID?
Setting the IsComposable
property will allow it to build. But as in our discussion, I don't know why your Phone
and Address
entities are not being generated.
[Query(IsComposable=false)]
public Contact GetContact(int contactId)
{
return DbContext.Contacts
.Include(c => c.Phones)
.Include(c => c.Addresses)
.SingleOrDefault(c => c.ContactId == contactId);
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK