2

I have a SPA using Angular and Breeze using WebAPI against MS SQL. In the data model booleans are represented as bit or integer. As I bind a checkbox to the angular model I want two way binding where checked = 1 and unchecked = 0. I understand the binding wants to work with strings.

I have looked at as many QAs here as I cand find on this topic but none seem exactly what I am looking for and I am also wondering if using Angular/Breeze/EF Pocos I should be changing something at the model level for what are essentially booleans so as to not "fight the framework".

This is also my first EF app. If i have SQL bit columns and call them boolean in my poco classes will EF take care of the conversion to 0 or 1?

I have to assume this wheel has been invented over and over but I am still wrapping my head around Angular.

<input type="checkbox" data-ng-model="haz.selected"  data-ng-true-value="1" data-ng-false-value="0"/>

1 Answer 1

1

This is also my first EF app. If i have SQL bit columns and call them boolean in my poco classes will EF take care of the conversion to 0 or 1?

EF will convert 0,1 to false,true respectively. If you serialize this value to angularjs. You just need to write:

<input type="checkbox" data-ng-model="haz.selected" />
Sign up to request clarification or add additional context in comments.

2 Comments

If I understand correctly, I should be able to define the column as boolean in the model and then Angular will be happy and EF will take care of the conversion. I'll try it and report back. Thanks
Changing data model to bool for values that will be bound to checkboxes fixes the problem for me. I thought it might be worth thinking about that before trying to fight against the natural flow of Angular data binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.