Is there an easy way to generate Javascript models based on POC Entity Framework entities (e.g. for ExtJs)?

I have an existing ASP.NET MVC3 application and you want to enable ExtJs primarily for creating diagrams, but for more functionality later. I already have a set of POCO objects in my architecture and would like all of them to be available for a javascript based model. In addition, I do not want to support two sets of objects. I suppose it's probably not difficult to write something that will create JSON representations of entities, but someone should have done it already, right? I could not find him in my search. Any help is appreciated!

+6
source share
4 answers

I don’t quite understand what you are asking, but maybe the C # compiler for JavaScript can help you. Alternatives that I know of:

0
source

This is an interesting idea! I can, of course, understand the motivation. A good solution would be to create a javascript file from your C # models using the T4 templating engine .

This way you can create a template that uses reflection to capture all the types defined in a particular project or namespace and iterate over them by writing out a javascript definition for each. A little more reflection for listing public property names and any javascript syntax that you would like to surround and you are all sorted!

0
source

You add a link to newtonsoft.json and you like it

var model = @Html.Raw(JsonConvert.SerializeObject(Model, new IsoDateTimeConverter())); 

Is this what you are looking for?

0
source

I was looking to do something simlar for a personal project and found a DataContractJsonSerializer on MSDN that would allow you to serialize your POCOs for JSON. There is also an article in the CodeProject article entitled Serializing and Deserializing JSON in ASP.NET by SummiG , which provides a good and at first glance complete example of creating a static helper class.

That being said, I have not tried it yet, and I will be grateful for any feedback if you go along this route.

-1
source

All Articles