Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:22:51+00:00 2026-06-17T18:22:51+00:00

Do you know how I could update an entity in WCF Data Services with

  • 0

Do you know how I could update an entity in WCF Data Services with OData syntax without the key property of the entity.

For example, an entity:

public class Product
{
    [Key]
    public int Id { get; set; }

    public string Reference { get; set; }
}

I would like to make this request:

PUT myservice.svc/Product('REFXX') 

with ‘REFXXX’ corresponding do the Reference property (which is unique).

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:22:52+00:00Added an answer on June 17, 2026 at 6:22 pm

    I wrote a IDispatchMessageInspector, parse the url and replace the match element in the request parameter with a correct syntax and the real key. I know that the key is not the real “Key” with a specific user agent or with the syntax Service.svc/Entity(SecondaryKey=value), which is used normally for multiple pk’s.

    so in the method AfterReceiveRequest the process is:

    • parse the url Service.svc/Entity(SecondaryKey=value)
    • get the key value of the entity (by building a dynamic linq expression)
    • change the match element of the request with Service.svc/Entity(PKValue)

             public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
      {
      
          if (request.Properties.ContainsKey("UriTemplateMatchResults") && HttpContext.Current != null)
          {
              //get match for current request
              UriTemplateMatch match = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
      
              Utils.ODataBasicUriParser uriParser = new Utils.ODataBasicUriParser(match.RequestUri.PathAndQuery);
      
              //verify if this is a SecondaryKey request
              if (uriParser.IsEntityQuery && uriParser.IsSecondaryKeyQuery)
              {               
                  //TODO this syntax is also used for entities with multiple pk's, test it
      
                  //get a new data context
                  //TODO see if this can be improved, avoid two datacontext for one request 
                  DataContext ctx = new DataContext();
      
                  Type outType;
                  //get entity type name from the service name 
                  string entityName = DataContext.GetEntityNameByServiceName(uriParser.EntityServiceName);
      
                  //get the pk for the entity
                  string id = ctx.GetEntityId(entityName, uriParser.EntityKey, uriParser.EntityId, out outType);
      
                  //verify if the pk has been found or cancel this to continue with standart request process
                  if (string.IsNullOrEmpty(id))
                  {
                      Trace.TraceWarning(string.Format("Key property not found for the the entity:{0}, with secondaryKeyName:{1} and secondaryKeyValue:{2}",
                          entityName, uriParser.EntityKey, uriParser.EntityId));
      
                      return System.Net.HttpStatusCode.NotFound;
                  }
      
                  //in odata syntax quotes are required for string values, nothing for numbers
                  string quote = outType.FullName == typeof(Int32).FullName || outType.FullName == typeof(Int64).FullName ? string.Empty : "'";
      
                  //build the new standart resource uri with the primary key
                  var newUri = new Uri(string.Format("{0}/{1}({2}{3}{2})", match.BaseUri.ToString(), uriParser.EntityServiceName, quote, id));
      
                  //create a new match to replace in the current request, with the new Uri
                  UriTemplateMatch newMatch = NewMatch(match, newUri); 
      
                  //set request values
                  request.Properties["UriTemplateMatchResults"] = newMatch;
                  request.Headers.To = newUri;
                  request.Properties.Via = newUri;
              }
          }
      
          return null;
      }
      
      
      UriTemplateMatch NewMatch(UriTemplateMatch match, Uri newUri)
      {
          UriTemplateMatch newMatch = new UriTemplateMatch();
          newMatch.RequestUri = newUri;
          newMatch.Data = match.Data;
          newMatch.BaseUri = match.BaseUri;
      
          return newMatch;
      }
      

    works for my current needs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I could just make all the Mix_Musics public, and not worry about
I would like to know how could I use JSON for passing data from
Update: Originally, this post was using Books as the example entity, with Books1 ,
This is how my entity class looks: @Entity @Unindexed public class User { ...
I have some code that I know could be nicer if it's done in
I know this could be done manually with some hardcoded Linq Joins. However, I
I know I could code what I'm trying to achieve, but I'd like to
I know I could solve this with a header but I'd rather not have
I know I could use PHP to do this, but wanted to find out
May I know how could I pass the value of driver from code behind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.