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 6839243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:41:44+00:00 2026-05-26T23:41:44+00:00

Simple experiment: I created an entity model from Northwind, and find that the generated

  • 0

Simple experiment: I created an entity model from Northwind, and find that the generated classes don’t work for protobuf-net v2 without adding the Order property. Is there a way to get the entity code generator to add Order, or is there a way to get protobuf-net to work without Order?

I have to change

[DataMemberAttribute()]

to

[DataMemberAttribute(Order=1)], etc.

NorthwindEntities e = new NorthwindEntities();

using(var file = File.Create("customers.bin"))
{
    Serializer.Serialize(file, e.Customers);
}
  • 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-05-26T23:41:44+00:00Added an answer on May 26, 2026 at 11:41 pm

    What is required is that it has a way to resolve members to numeric keys. This can take the form of inline attributes – for example, it allows [DataContract]/[DataMember(Order=key)], [XmlType]/[XmlElement(Order=key)], or [ProtoContract]/[ProtoMember(key)].

    There are also options via [DataContract] to infer the contract alphabetically, but this is only safe if your contract type is not going to change in the future; to do this, add:

    [ProtoContract(InferTagFromName = true)]
    

    to the type (perhaps in a partial, see below). This applies directly to the scenario you present, where [DataMember] indicates the members, but there is no defined Order. Personally I prefer explicit layouts, for stability.

    Another option doesn’t even need hints like [DataMember]; you can ask it to apply either BinaryFormatter rules (all fields, public or private), or XmlSerializer rules (public members, properties or fields); again, though, this is very unstable if your type changes!

    [ProtoContract(ImplicitFields = ImplicitFields.AllPublic)]
    

    But; another common scenario is that you have types coming from a generator, that you can’t conveniently edit, since any edits would get lost at re-generation; for that scenario, partial classes can be helpful. You can’t add attributes to members via attributes, but [ProtoPartialMember] can help here. For example, in a separate code file:

    [ProtoContract]
    [ProtoPartialMember(key, memberName)]
    [ProtoPartialMember(anotherKey, anotherMemberName)]
    ...
    public partial class Order {}
    

    Sometimes, you have no access whatsoever to the type, so adding attributes of any kind is not an option. If your scenario is as you describe ([DataContract/[DataMember], noOrder`), then a lazy option is to enable this globally:

    Serializer.GlobalOptions.InferTagFromName = true;
    

    or in v2:

    RuntimeTypeModel.Default.InferTagFromNameDefault = true;
    

    For more complex scenarios, v2 has a new MetaType model devoted to this, where you can configure the layout at runtime:

    RuntimeTypeModel.Default.Add(typeof(Order), false)
                .Add(key, memberName).Add(anotherKey, anotherMemberName);
    

    or if your keys are 1, 2, 3, … then just:

       RuntimeTypeModel.Default.Add(typeof(Order), false)
                .Add(memberName, anotherMemberName, ...);
    

    (there are a myriad of options on the MetaType to control all aspects of the serialization)

    I think that covers most of the options here!

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

Sidebar

Related Questions

I want something simple in order to experiment/hack. I've created a lot interpreters/compilers for
I am implementing a simple RoR webpage that collect emails from visitors and store
I've written an experimental function evaluator that allows me to bind simple functions together
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
Simple question, but one that I've been curious about...is there a functional difference between
Simple question that keeps bugging me. Should I HTML encode user input right away
I've developed a simple webflow in Grails (mostly to experiment with using webflows- its
How do I create an app that is: lightweight: I am guessing don't require
I have done a simple experiment to test MongoDB's performance and disk usage. I
I'm trying to create a simple app that draws rectangles within the Canvas tag.

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.