Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Framework Validation errors not being handled correctly by breeze.sharp client. #3

Open
chrismon opened this issue May 16, 2014 · 8 comments

Comments

@chrismon
Copy link

This issue is in the 0.5.4 release of Breeze.Sharp. Not sure if it should be fixed in Breeze.Sharp or perhaps Breeze.ContextProvider.EF6, but there seems to be a disconnect between expected behaviors.

Unexpected Behavior:
I have a .Net Web API BreezeController that contains an EF6 repository.

If I perform object level validation via BeforeSaveEntities override, where the guidance is to fail validation by throwing an EntityErrorsException, the Breeze.Sharp client catches this as expected and all is well.

If, however, I perform attribute level validation using an Entity Framework ValidationAttribute class, instead of an EntityErrorsException, failures are returned to the Breeze.Sharp client as a SaveResult containing an Errors collection. In this case, the client throws an exception: Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JArray'. This exception occurs when Breeze.Sharp tries to parse the SaveResult's KeyMappings array, which is null.

Workaround:
For now, rather than changing all of my Validation Attributes to throw an EntityErrorsException, I resolved this in my BreezeController's SaveChanges method by checking the returning SaveResults for any errors, and if found, wrapping those errors in an exception that I then throw to the client:

[HttpPost]
public SaveResult SaveChanges(JObject saveBundle)
{
    var saveResult = _unitOfWork.Commit(saveBundle);
    if (saveResult.Errors != null && saveResult.Errors.Count > 0)
    {
        var errors = new List<EntityError>();
        foreach (var error in saveResult.Errors)
        {
            var entityError = error as EntityError; //errors are stored as List<object> in the SaveResult
            if (string.IsNullOrEmpty(entityError.ErrorMessage))
            {
                entityError.ErrorName = "Attribute Validation Error";
            }
            errors.Add(entityError);
        }
        throw new EntityErrorsException(errors);
    }
    return saveResult;
}
@ponmani
Copy link

ponmani commented Jun 5, 2014

Hi chrismon,

Can you please samples breeze.sharp using SPA(single page applications). Samples
1)Controller
2)Views(Html)
3)viewmodel(javascript)
4)Breeze.sharp using examples

@chrismon
Copy link
Author

chrismon commented Jun 5, 2014

Hello, yes I have reviewed samples and am working with an Angular application as well at the moment without issues. The issue I ran into with this post was while communicating with my Breeze service from a new Breeze.Sharp .Net client I am working on.

If there is something I am doing wrong in the service that you think the samples would help me understand, could you please expand on that?

@ponmani
Copy link

ponmani commented Jun 5, 2014

Hi chrismon,

I know chirsmon you expected breeze.sharp worked many project . But I am beginner of the breeze.sharp. How do i used breeze.sharp i don't know. So can you help little examples. Please

@steveschmitt
Copy link
Member

ponmani, please do not use github to ask for examples. It is for reporting bugs only. StackOverflow is the place for questions.

Also, you have some confusion about breeze.sharp. Breeze.sharp is a client-side framework that runs in the .NET platform. If you were writing a desktop application using Windows Forms or WPF, or a Windows 8 application, you would use breeze.sharp.

If you want to use HTML and JavaScript, you would use breeze.js on the client. There are plenty of samples and tutorials using breeze.js.

If you are using ASP.NET on the server, you would use breeze.server.net. It works with Entity Framework and NHibernate to make it easy to write a backend for your breeze.js or breeze.sharp client.

If you have any further questions, please ask them on StackOverflow

@ponmani
Copy link

ponmani commented Jun 6, 2014

Oh. Thank u. Yes I already confused breeze.sharp is server side framework.
But not now I am not confused. Thank you

On Fri, Jun 6, 2014 at 2:13 AM, Steve Schmitt [email protected]
wrote:

ponmani, please do not use github to ask for examples. It is for reporting
bugs only. StackOverflow
http://stackoverflow.com/questions/tagged/breeze is the place for
questions.

Also, you have some confusion about breeze.sharp. Breeze.sharp is a
client-side framework that runs in the .NET platform. If you were writing a
desktop application using Windows Forms or WPF, or a Windows 8 application,
you would use breeze.sharp.

If you want to use HTML and JavaScript, you would use breeze.js
https://github.com/Breeze/breeze.js on the client. There are plenty of
samples http://www.breezejs.com/samples and tutorials
https://www.google.com/#q=breeze+js+tutorial using breeze.js.

If you are using ASP.NET on the server, you would use breeze.server.net
https://github.com/Breeze/breeze.server.net. It works with Entity
Framework and NHibernate to make it easy to write a backend for your
breeze.js or breeze.sharp client.

If you have any further questions, please ask them on StackOverflow
http://stackoverflow.com/questions/tagged/breeze


Reply to this email directly or view it on GitHub
#3 (comment).

@ponmani
Copy link

ponmani commented Jun 6, 2014

I already used breeze.js an breeze controller in durandal framework.
Because I doubt breeze.sharp is controller. It is not clent side framework.
Thank you for your solutions.

On Fri, Jun 6, 2014 at 9:35 AM, Pon Mani [email protected] wrote:

Oh. Thank u. Yes I already confused breeze.sharp is server side framework.
But not now I am not confused. Thank you

On Fri, Jun 6, 2014 at 2:13 AM, Steve Schmitt [email protected]
wrote:

ponmani, please do not use github to ask for examples. It is for
reporting bugs only. StackOverflow
http://stackoverflow.com/questions/tagged/breeze is the place for
questions.

Also, you have some confusion about breeze.sharp. Breeze.sharp is a
client-side framework that runs in the .NET platform. If you were writing a
desktop application using Windows Forms or WPF, or a Windows 8 application,
you would use breeze.sharp.

If you want to use HTML and JavaScript, you would use breeze.js
https://github.com/Breeze/breeze.js on the client. There are plenty of
samples http://www.breezejs.com/samples and tutorials
https://www.google.com/#q=breeze+js+tutorial using breeze.js.

If you are using ASP.NET on the server, you would use breeze.server.net
https://github.com/Breeze/breeze.server.net. It works with Entity
Framework and NHibernate to make it easy to write a backend for your
breeze.js or breeze.sharp client.

If you have any further questions, please ask them on StackOverflow
http://stackoverflow.com/questions/tagged/breeze


Reply to this email directly or view it on GitHub
#3 (comment).

@jtraband jtraband reopened this Aug 25, 2014
@ponmani
Copy link

ponmani commented Nov 18, 2014

Hi steveschmitt,

I can't undertsand breeze.js and breeze.sharp.But I know that breeze.js and breeze controller using single page application. Can you explain breeze.sharp topic with your simple examples.

@steveschmitt
Copy link
Member

Hi ponmani,
Please post questions on StackOverflow.
Ideablade also offers support and consulting - contact [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants