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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:43:58+00:00 2026-06-17T01:43:58+00:00

Has anyone written a utility that will convert Breeze metadata (captured from entity framework

  • 0

Has anyone written a utility that will convert Breeze metadata (captured from entity framework data attributes) into knockout validation extensions (using knockout.validation)?

  • 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-17T01:43:59+00:00Added an answer on June 17, 2026 at 1:43 am

    I have made an function that reads the metadata from an entity and adds validation rules.

    app.domain.indicador = (function () {
    "use strict";
    var constructor = function () {...}
    var initializer = function indicadorInitializer(entity) {
        var entityType = entity.entityType;
        if (entityType) {
            console.log(entityType);
            for (var i = 0; i < entityType.dataProperties.length; i++) {
                var property = entityType.dataProperties[i];
                console.log(property);
                var propertyName = property.name;
    
                var propertyObject = entity[propertyName];
                if (!property.isNullable) {
                    propertyObject.extend({ required: true });
                }
                if (property.maxLength) {
                    propertyObject.extend({ maxLength: property.maxLength });
                }
            }
    
            for (var i = 0; i < entityType.foreignKeyProperties.length; i++) {
                var property = entityType.foreignKeyProperties[i];
                console.log(property);
                var propertyName = property.name;
    
                var propertyObject = entity[propertyName];
                if (!property.isNullable) {
                    propertyObject.extend({ required: true });
                }
                if (property.maxLength) {
                    propertyObject.extend({ maxLength: property.maxLength });
                }
                //Bussines rule
                propertyObject.extend({ notEqual: 0 });
            }
        }
    };
    return {
        constructor: constructor,
        initializer: initializer
    };
    })();
    

    I use the function as initializer:

    store.registerEntityTypeCtor("Indicador", domain.indicador.constructor, domain.indicador.initializer);
    

    It’s just a start but for the time is useful for me.

    Update:

    I changed the way I add validation. I share it here in case it is useful to someone:

    Helper object:

    app.validatorHelper = (function (breeze) {
    var foreignKeyInvalidValue = 0;
    
    function addDataTypeRules(dataType, property) {
        switch (dataType) {
            case breeze.DataType.DateTime:
                //TODO: implement my function to validate dates. This validator is too permissive
                property.extend({ date: true });
                break;
            case breeze.DataType.Int64:
            case breeze.DataType.Int32:
            case breeze.DataType.Int16:
                //it's needed to accept negative numbers because of the autogenerated keys
                property.extend({ signedDigit: true });
                break;
            case breeze.DataType.Decimal:
            case breeze.DataType.Double:
            case breeze.DataType.Single:
                property.extend({ number: true });
                break;
        }
    };
    
    function addValidationRules(entity) {
        var entityType = entity.entityType;
        if (entityType) {
            for (var i = 0; i < entityType.dataProperties.length; i++) {
                var property = entityType.dataProperties[i];
                //console.log(property);
                var propertyName = property.name;
                var propertyObject = entity[propertyName];
    
                addDataTypeRules(property.dataType, propertyObject);
    
                if (!property.isNullable) {
                    propertyObject.extend({ required: true });
                }
                if (property.maxLength) {
                    propertyObject.extend({ maxLength: property.maxLength });
                }
            }
    
            for (var i = 0; i < entityType.foreignKeyProperties.length; i++) {
                var property = entityType.foreignKeyProperties[i];
                //console.log(property);
                var propertyName = property.name;
                var propertyObject = entity[propertyName];
    
                addDataTypeRules(property.dataType, propertyObject);
    
                if (!property.isNullable) {
                    propertyObject.extend({ required: true });
                    //Bussiness Rule: 0 is not allowed for required foreign keys
                    propertyObject.extend({ notEqual: foreignKeyInvalidValue });
                }
                if (property.maxLength) {
                    propertyObject.extend({ maxLength: property.maxLength });
                }
            }
        }
    };
    
    return {
        addValidationRules: addValidationRules
    };
    })(breeze);
    

    The custom validator:

    (function (ko) {
    ko.validation.rules['signedDigit'] = {
        validator: function (value, validate) {
            if (!validate) return true;
            return ko.validation.utils.isEmptyVal(value) || (validate && /^-?\d+$/.test(value));
        },
        message: 'Please enter a digit'
    };
    
    ko.validation.registerExtenders();
    })(ko);
    

    Using the helper at the initializer:

    app.domain.valorIndicador = (function (vHelper) {
    "use strict";
    var constructor = function () {
    };
    
    var initializer = function indicadorInitializer(entity) {
        vHelper.addValidationRules(entity);
    };
    
    return {
        constructor: constructor,
        initializer: initializer
    };
    })(app.validatorHelper);
    

    And setting the initializer:

    store.registerEntityTypeCtor("ValorIndicador", domain.valorIndicador.constructor, domain.valorIndicador.initializer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone written a macro that will remove and sort your usings in an
Has anyone written, or know of a query, that will find and drop all
I have a simple single threaded utility written in C# that inserts data into
Has anyone written either a long or short program in COW that demonstrates what
Has anyone written a Fast Algorithm that generates a LARGE dummy file in PHP,
Has anyone written a fast Fourier transform extension for R that modifies R's native
Has anyone written Go bindings for Subversion? By that I mean for programmatic access
Has anyone written iPhone classes that mimic the behavior of the Application Settings? It
Has anyone written a formal paper describing a method to (automatically) convert functions to
I have a small utility app written in Visual Basic 6 that has been

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.