I am using Asp.NET MVC as a basic webservice for several searchengine type asp/ jquery sites. Database searching is straightforward:
Model - Sql Server FullText Sproc returning XML
View - N/a
Controller - Authorise user/ Parse input return Content (Model.XML)
The returned XML contains four resultsets - item list, category breakdown, related/ads items & paging numbers. The item, category & related lists all comprise several elements and attribs.
I am now looking for the best method to display the same info in an MVC view - both full and partials for jquery use - but am struggling to find the best solution. The only two I have come up with so far are to parse the XML using Linq ( should this be done in View or Controller?) or have a SProc returning resultsets and use NextResult method to fill multiple lists ( not that I 've worked out how to do that yet....)
All suggestions appreciated, thanks!
Decided to run with XDocument(Linq-to-XML); with the PasteXmlAsXLinq Visual Studio addin taking the pain out of it!
I'll leave the ORM until Asp.net mvc rtm. By then should have a better idea (Entity/ Linq & Viewengine) on most suitable route for full MVC 'conversion'.
For parsing the xml - how about using XmlSerializer to deserialize an object graph?
Does it need to return xml? How about returning regular grids, that you can read over directly? For example, one option is to use ORM such as a LINQ-to-SQL DataContext - then you can just execute the generated method which gives you the data as objects.
Alternatively - perhaps render the xml via an xsl transform?
Related
I want to use on entity framework with elastic search.
I saw this article MVC APPLICATION WITH ENTITY FRAMEWORK AND ELASTICSEARCH.
But as I understood, I need 2 DB (ms sql+ elastic) and there they explain how to translate the data.
The ms sql I will save the data and I done the search on the elastic .
So all the data will be twice so it will be waste of storage...
Is there any direct way to do that?
thanks
You can use entity framework with elastic search by utilising ElasticsearchCrud api.
This article clearly explains the steps to do so.
P.S: I rather not to copy/paste the steps here as it might look redundant.
Yes you understood right you would need to use two different sources.
There is no direct way to use elasticsearch with EF, you would need to write you custom logic to fit Database and Elasticsearch together.
If you ask why? Answer is that Database and Elasticsearch are different.
First of all Elastic is document database and you should save whole object while in database you can split items to multiple tables in ES "preferable" to save as a one document (Still in ES you can use nested objects but you will not be able to join).
Secondly search queries are totally different in SQl and Elastic. So sometimes only you would decide which source should be used to search. To search Elastic you can use NEST package but you would need to learn ES queries and indexing part since depends on analysis you will have defferent results.
Good morning,
I am working on new MVC4 apps which consist of a huge search form (more than 50 parameters).
After the form is submitted, a complex query is built and i obtained a IList of a viewModel:
IList<ResultViewModel> results = session.CreateSQLQuery(ComplexQuery).SetResultTransformer(Transformers.AliasToBean<ResultViewModel>()).List<ResultViewModel>();
InterfaceVM.QueryResults = results;
InterfaceVM is then the model used by my output views to display grid results and Leaflet maps.
Everything works fine except that i can get results up to 1 million records. I would need to implement paging using PagedList.MVC for example but without having to pass the search parameters in the URL. I would like to avoid rebuilding the query and the IList object again and again.
InterfaceVM.QueryResults =results.ToPagedList(pageNumber, 20);
Moreover, this IList results will also be used several times in my output views to generate dynamically complex GIS outputs.
I spent several hours reading over the web to find the best strategy to keep my result object persisting after the form has been submitted to be able to manipulate it easily and avoiding to rebuilt it for each paging/mapping request.
I read about temp table in SQL server, Session object, MemoryCache etc... but i don't know what would better fit my situation.
Your input on this would be really helpful. I am using Fluent NHibernate, MVC4, SQL server 2008 R2.
Thanks in advance for your help
Sylvain
I have a web app that we're still stuck in asp.net 2.5 with. We've started using some newer technology with our front end, including loading some of our data into JSON objects and passing them around the application using localStorage. It's working really great.
In the future we're going to change our ASP.NET web form architecture into ah HTML5/JQuery front and Web API back end. So we're trying to write for that future while still being constrained to our old web form post backs and business objects. So right now we're posting from our search form to our search result page web form and we'll be calling a method from our business object to grab and return search results.
The criteria object we pass in has 20 or so values and a couple of collections (product line ID's, category ID's, etc..). So it's a slightly complicated object. In the old form we grabbed values from the controls, validated them, and passed them in using the asp.net controls, it was a single form solution. Our new solution has a search form and a results page. We're passing our values from form to form in a JSON object in internal storage. I can't really get to that from server side so I also stashed the values in a hidden field on the form that I can grab on the server side when I POST to the results page (eventually we'll call an API from the new form using ajax). So now that I can see the data, how do I parse and work with a JSON object in the code behind of asp.net. I need to load the 20 or so search criteria values and iterate through the ID collections (Guid and int) to load them into the same criteria object. This object is then passed in as the search methods parameter and search results will come back. Not sure how to manipulate the json on the server side.
If I understand the question, you have a JSON string in the server, and you just need to work with it.
Easiest way is to define a class (or in this case, a few classes) representing the data, then simply deserialize the JSON into an instance of the class. From there, you've got a regular object, and can do whatever you need with it, including serializing it back to JSON if you want.
With JSON.NET (aka Newtonsoft.Json), it's as simple as:
var myObject = JsonConvert.DeserializeObject<SomeType>(jsonString);
If you need help building the class, you can use json2csharp, where you can pass in a sample JSON file, and it builds the appropriate C# classes for you.
You can use DataContractJsonSerializer class, if the .Net framework is upgrade to 3.5 or later.
But, I found this article in web, http://www.netfxharmonics.com/2008/01/DojrNET-Dojo-RPC-Library-NET-20,
which is using Dojr.Net library and its compatible with .Net 2.0.
Hope this helps.
I have a question for you stackoverflow experts :). I'm planning to use the FLOT jQuery plugin to chart some data to the MVC3 application I'm building.
I have several views that return data, but I'm just using a resultset and not an entity framework of any sort (it's nice and fast). I've never worked with JSON before, and I have the following questions:
a) Do I have to use a data model to return data to the controller, then use the JSON method to create the JSON file, or can I return the data without using an entity framework and achieve the same result?
b) Is there a bit of sample code anywhere that can help me out with this (or a link to a good example?
Many thanks in advance ;-).
If you can get your data into a class with properties (get;set;) then you can simply use the built in serializer for MVC ie return Json(yourClass);
If you want a bit more control over it, check out
http://json.codeplex.com/
Theres a linq-to-json and a dataset converter as well.
I have a couple of super simple databases. Basically they all consist of single tables that saves tracking/logging data etc.
Now I want to list this data but I'd like to find a solution that's applicable to all the different tables in all the databses. SO basically I'm looking for some way/some pattern of pointing a solution to a database, generate code and GUI and the publish the site. The tables can have huge amount of rows so I need functionally like paging etc but otherwise a simple list is all I'm looking for as a first step. I've been looking at Dynamic Data from MS - could this work? Other options? I'd really like the web sites to me ASP.NET MVC ...
As a seconds step I'd also like to have the possibility to change/add and delete data from the rows via the GUI.
Consider using ASP.NET MVC 2. It has extensive scaffolding capabilities that can auto-generate the views for you, yet allows a lot of fine tuning
Brad Wilson explains scaffolding here: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html
For MVC 2, see
http://aspnet.codeplex.com/
and
http://www.asp.net/mvc/download/
Paging is not included, but you can get that from MVCContrib, for example
You could roll your own scaffolding and generate the actual pages using T4 (http://www.olegsych.com/2007/12/how-to-create-a-simple-t4-template/ and others), or you could look into monorail (http://www.castleproject.org/monorail/index.html).
If you don't mind mandatory JavaScript then I would suggest jqGrid. It should be very simple to enumerate tables, columns, and generate jqGrid's columns from it (colModel). You can see an example of how I do a similar thing here - it does almost exactly what you need but for classes, not database. So, you can't use the solution "as is" because it's for domain classes, but it is very close, you can take it as a base and rewrite JqGridExtensions.JqGridModel to process db table definition, not domain class definition.
If your site has to work without JavaScript, then either MVC v2 with scaffolding will work, or you can try S#arp Architecture which also includes its own scaffolding out of the box, that generates full CRUD model/controller/views/repositories/etc. The benefit here is that you will still work with classes, not datasets. However as far as I understand you'll have to define scaffolding manually for each entity - but since scaffolding is very flexible, I'm sure you can write Uber-Scaffolding class that will enumerate your database and spit out sub-scaffolding files or just call them right away. A quote:
you programmatically create an object
called EntityScaffoldingDetails which
holds details such as the entity name,
the namespace, along with property
details such as the property name,
type, domain signature inclusion,
attributes, default test values, and
SQL generation details.
But, I better like the jqGrid way, because it's very easy to generate jqGrid model definition from the database schema which usually contains all the metadata. Of course, one can integrate S#arp scaffolding and jqGrid so that the first produces the latter. The benefit of scaffolding is that you have full control over the code, you can take it and tweak it. Because, you can't expect it to be 100% automatic - generator can't decide HasMany or ManyToMany, control type, hidden fields, etc. Of course you can use SQL metadata (properties maybe) to give hints for your scaffolding generator.
Now, if you need a ready out-of-the-box solution, I don't think there's one except for maybe commercial tools. The above will only allow you to assemble your own one. As for commercial tool, for example, Telerik Grid said to be able to "automatically infer its columns based on the properties of the data item it is bound to".