views:

43

answers:

2

Hello,

Can anybody tell me how to customize the OData feed for Ado.Net Data Services using Entity Framework (Code First/Only)?

There is no EDMX file (as it is Code Only).

I have tried adding the attribute:

[EntityPropertyMapping( "Id" , SyndicationItemProperty.Title , SyndicationTextContentKind.Plaintext , true )]

To my POCO entity classes but nothing shows up in the feed title tag?

UPDATE:

If I was using an EDMX file I could customize the feed by applying attributes like this:

<EntityType Name="Customer">
  <Property Name="myAddress" Type="MyModelNamespace.Address"
        me:EpmSourcePath="Street"
        m2:FC_Atom="true"
        m2:FC_TargetPath="EpmSyndicationTitle"
        m2:FC_ContentKind="EpmPlaintext"
        m2:FC_KeepContent="true"/>
</EntityType>

But I am not using an EDMX file - I am using Code Only. My question is about achieving the same thing when using Code Only (no XML file).

Thanks!

A: 

Does this help?

http://blogs.msdn.com/b/alexj/archive/2010/06/11/tip-56-writing-an-odata-service-using-the-reflection-provider.aspx

Raj Kaimal
Hi Raj, the article you provided was where I got the idea for using the EntityPropertyMapping attribute. But it would seem (unless I am doing something very stupid) that that attribute only applies to the Reflection Provider. I am using the Entity Framework Provider (in "Code First" configuration).
Jamie
A: 

Have you set the access rules for your entity sets?

as a catch all for testing you should have something like:

public class NorthwindService : DataService<NorthwindEntities>
{
   public static void InitializeService(IDataServiceConfiguration config)
   {
      config.SetEntitySetAccessRule("*", EntitySetRights.All);
    }
}
Doobi
Thanks for the reply Doobi. I do have the access rules working fine. It isn't about missing data - it all gets returned. It is just about copying/moving some of the data into the <title></title> section of the OData feed (something that is very easy when using the Reflection Provider or Entity Framework with an EDMX file).
Jamie