jshirota / PreStorm

A Parallel REST Client for ArcGIS Server
17 stars 2 forks source link

Domain value and code in same object #1

Open BHare1985 opened 9 years ago

BHare1985 commented 9 years ago

Great client. I am considering modifying it to support Esri's new roads and highway extension to MapServers. (Supports queryAttributeSet which takes an LRS (Linear reference system) and queries multiple layers at once)

I ran into a use-case that I think could be useful to some, and that is getting the domain translated value and it's code both in the result. For example in the object model

        [Mapped("STATUS", "dStatus")]
        public virtual string StatusTranslated { get; protected set; }

        [Mapped("STATUS")]
        public virtual string StatusCode { get; protected set; }

Where dStatus is the domain for STATUS and StatusTranslated is the STATUS field with it's domain value and StatusCode is the code field of STATUS. Currently it errors out because I think duplicate mapping of STATUS. A few work arounds seem to exist to accomplish what I want, taking advantage of GetCodedValueByName in Esri but its internal, or using Service.Domains and do a lookup manually. Just thought this use-case may be an easy feature to add, although allowing multiple mappings this way may violate your design intent.

Thanks and keep up the great work.

jshirota commented 9 years ago

There's actually one more overload for the constructor that takes the string formatter. If you put "Invalid code found: {0}", and your database contains say 123, which is not a valid coded value domain key, this results in "Invalid code found:123".

public Mapped(string fieldName, string domainName, string invalidCodeFormat = null)

This is not an ideal solution. It should really be a delegate, but it's an attribute class, so I couldn't put a delegate type in the constructor argument. Anyway, Esri domain does not enforce referential integrity, so we often end up with more work managing it. This automatic domain mapping in PreStorm is provided mostly for one-way conversion (i.e. for reporting), and in this case, the string formatter is good enough. If you're table is guaranteed to never violate the domain, then, you could actually use this for 2-way conversion and insert/update. This means, you assign the string description to the property and invoke Update(), and the corresponding domain key is stored in the table. However, I can't think of a situation where you have to do this. It's almost better to deal with the key in the database, and the human-readable description can come from a combobox, which binds to the domain key value pairs.

On Tue, Aug 11, 2015 at 6:43 PM, Brian Hare notifications@github.com wrote:

Great client. I am considering modifying it to support Esri's new roads and highway extension to MapServers. (Supports queryAttributeSet which takes an LRS (Linear reference system) and queries multiple layers at once)

I ran into a use-case that I think could be useful to some, and that is getting the domain translated value and it's code both in the result. For example in the object model

    [Mapped("STATUS", "dStatus")]
    public virtual string StatusTranslated { get; protected set; }

    [Mapped("STATUS")]
    public virtual string StatusCode { get; protected set; }

Where dStatus is the domain for STATUS and StatusTranslated is the STATUS field with it's domain value and StatusCode is the code field of STATUS. Currently it errors out because I think duplicate mapping of STATUS. A few work arounds seem to exist to accomplish what I want, taking advantage of GetCodedValueByName in Esri but its internal, or using Service.Domains and do a lookup manually. Just thought this use-case may be an easy feature to add, although allowing multiple mappings this way may violate your design intent.

Thanks and keep up the great work.

— Reply to this email directly or view it on GitHub https://github.com/jshirota/PreStorm/issues/1.