I have an MVS project where I use an AJAX to retrieve an array...
The following is my class on C#... I retrieve a list of 19,500 records... basically I pull an IEnumerable
public partial class VW_Suppliers
{
public int SupplierID { get; private set; }
public string Name { get; private set; }
public int SolarNumber { get; private set; }
public bool TpiClassification { get; private set; }
public int ValueStreamID { get; private set; }
public string ValueStream { get; private set; }
public int StatusID { get; private set; }
public string Status { get; private set; }
public string SupplierCode { get; private set; }
public int PurchaseSystemID { get; private set; }
public string PurchaseSystem { get; private set; }
public int AddressID { get; private set; }
public int AddressTypeID { get; private set; }
public string AddressType { get; private set; }
public string Street1 { get; private set; }
public string Street2 { get; private set; }
public string PoBox { get; private set; }
public string City { get; private set; }
public string PostalCode { get; private set; }
public int StateID { get; private set; }
public string StateCode { get; private set; }
public string State { get; private set; }
public int CountryID { get; private set; }
public string CountryCode { get; private set; }
public string Country { get; private set; }
}
[HttpGet]
public ActionResult GetSuppliersData()
{
JsonObject jsonObject;
IEnumerable<ViewSupplierVM> suppliers = _supplierService.GetAllSuppliers();
JsonResult jsonResult = Json(suppliers, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
However, I noticed two things... when using breakpoints I noticed that after I hit return... it takes around 10 seconds for AngularJS to hit the breakpoint when the data is received. Second problem is that whenever the page is ready with all data... the overall site is rather slow... for instance.. you type on a textbox, and everything appears from 0.5 to 4 seconds after typing... which leads me to believe that that array of 19,500 elements is consuming to much memory...
It is required that all suppliers appear on the first screen, so there is no way to turn this requirement around.
Any tips? What tricks could be done on the MVC controller to send to front end faster and prevent site from being to slow?
Loading and rendering 19,000 is in no way viable to me. I too just worked on an application in which a customer would need to be able to manage all their products (15,000+). The initial implementation was done using pagination for which this answer solved it out really nicely for me. But a more elegant solution is to implement some type of infinite-scroll mechanism, for which I have used ngInfiniteScroll (https://sroze.github.io/ngInfiniteScroll/). Now this solves one part of the problem for you, and that is your page being slow due to massive HTML renders, but in no case retrieving 19,000 items from the server in one shot is a good idea. Not only it stresses the database immensely, but if hosted on a live server you shall see quite a significant delay when the request for the data is made. I suggest pulling your data 20, 30, 100 at a time. For this myPagingFunction from ngInfiniteScroll should be just the right place to implement.
Related
I'm using WPF and still relatively new.
I haven't yet made the jump to MVVM, still trying to wrap my head around it.
I currently have a small app which extracts data from 4 different sources (at different times) and then displays it on a datagrid.
The issue is that the data model from the responses differs and I want to be able to easily use the same datagrid.
EG.
Datagrid binds to a model [zephyrPatientData]
Firstname : binds to firstName
last name: binds to lastName
ONE of the extractions has:
Firstname = firstName;
lastName = SURNAME.
Therefore if I use this data and try and bind to the datagrid, the LASTNAME firle is not filled as that model doesn't have lastName, it has surname.
Below: the datamodel that is working with the datagrid.
public class zephyrPatientData
{
public int CustomerID { get; set; }
public int ClaimID { get; set; }
public string ChemistID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ClaimNumber { get; set; }
public bool concern { get; set; }
public int? InsCompID { get; set; }
public string InsCompName { get; set; }
public int? EmployerID { get; set; }
public string EmployerName { get; set; }
public string DateOfInjury { get; set; }
public string dateOfBirth { get; set; }
public string Address { get; set; }
public int? SuburbID { get; set; }
public string SuburbName { get; set; }
public string Postcode { get; set; }
public string custPhone { get; set; }
public int? claimTypeID { get; set; }
public string InvoiceTo { get; set; }
public string Comments { get; set; }
public string ClaimManager { get; set; }
public string Injury { get; set; }
public bool activeClaim { get; set; }
public string ClaimManagerEmail { get; set; }
public int? LawyerID { get; set; }
public string LawyerCompany { get; set; }
public double? outstandingScripts { get; set; }
public double? outstandingValue { get; set; }
public string dispenseConnected { get; set; }
public string dispenseID { get; set; }
}
Below: The Datamodel I want to work with the datagrid.
public class zDispensePatientData
{
public string id { get; set; }
public int clientNo { get; set; }
public string firstName { get; set; }
private string surname;
public string lastName
{
get
{
return surname;
}
set
{
surname = value;
}
}
public string title { get; set; }
public object licenseNo { get; set; }
public string sex { get; set; }
public object dateOfBirth { get; set; }
public object postalAddress { get; set; }
public object postalSuburb { get; set; }
public object postalState { get; set; }
public object postalPostCode { get; set; }
public string homeAddress { get; set; }
public string homeSuburb { get; set; }
public string homeState { get; set; }
public string homePostCode { get; set; }
public string phoneNumber { get; set; }
public string mobileNumber { get; set; }
public object faxNumber { get; set; }
public string email { get; set; }
public DateTime lastModified { get; set; }
public bool active { get; set; }
public bool deceased { get; set; }
}
As you can see...I TRIED to use the get;set; section of the [zDispensePatientData] however I have no idea how to use this correctly.
In reality in laman's terms I want it to read surname from the API response but then be accessible as lastName in for use in the Datagrid.
The reaons for this is that there will be another 4 [zDispensePatientData] (other names) and all will have different field names but in the end I need them to work in the same datagrid without changing the binding of every single datagrid column.
EDIT: Expanded the question:
So I appreciate the responses but I'm not exactly grasping how to get this done.
If I were to take away all the model fields and just leave... 3:
firstName
lastName
patientID
my task is to have 5 different models (from responses from API's) 'allocate' to my own model.
eg.
<my model>
public string id { get; set; }
public string lastName { get; set; }
public string firstName { get; set; }
<model API 1>
public string id { get; set; }
public string patientLastName { get; set; }
public string patientFirstName { get; set; }
<model API 2>
public string patientid { get; set; }
public string surname{ get; set; }
public string FIRSTNAME{ get; set; }
Any app will only ever have one connection ([dispenseType]).
So I guess what I need is checking the user dispenseType and then using the model from the API they are using.
Or is it possible to SET myModel based on the contents of the other models.
eg.
if
API1.firstName = null
myModel.firstName = api2.FIRSTNAME
My main issue is I don't know the concept or question to ask. If there is a pointer to the terminology of what I'm trying to achieve I'm happy to go out and learn it to implement it.
If the column in the DataGrid binds to a property named "LastName", you need to make sure that the type T in the IEnumerable<T> ItemsSource of the DataGrid has such a property.
So add one to the zDispensePatientData class like you have currently done:
public string LastName
{
get => surname;
set => surname = value;
}
Another option is to set or bind the ItemsSource to a an IEnumerable<ViewModel> where the ViewModel class has the properties that the DataGrid expects.
You would then translate each zephyrPatientData and/or zDispensePatientData object to a ViewModel, e.g.:
sourceCollection = zDispensePatientDatas
.Select(x => new ViewModel() { LastName = x.Surname } );
How to map properties of two different objects?
This question answers my question but was stated in a better way than I could
I'm working on an ASP.net Web API application and would like to allow multiple users to have access to their own data without changing the database schema too much.
My tables look a little like this:
public class Asset
{
public string Name { get; set; }
[Required]
public int Id { get; set; }
public string AssetTag { get; set; }
public string Serial { get; set; }
public int Model { get; set; }
}
public class Organisation
{
[Required]
public int Id { get; set; }
[Required]
public int DefaultLocation { get; set; }
public location Location { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public string Contact { get; set; }
}
public class AssetModel
{
public string Name { get; set; }
[Required]
public int Id { get; set; }
public int CategoryId { get; set; }
public int ManufacturerId { get; set; }
public string ModelNumber { get; set; }
}
*fields omitted for brevity
Each user should be able to create their own assets / organisations / etc, but should not have access to any other users fields.
I'm yet to add authorization / authentication however I'm probably going to use token based auth as outlined here:
http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/
Should this be as easy as tacking each users GUID onto each column and applying some logic? Or will I need to completely re-design the database?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Newbie here.
I've got a C# Windows Presentation Forms program and I'm trying to add a method that downloads the string of a JSON webpage and then creates a list of events (each of which has a list of teams attending) from the data in the page. The only problem is that the JSON.NET documentation is confusing me and I can't seem to get a grasp on JSON format in general.
For reference, there are two parts to this method:
1) get the list of "official" events (if you look you will notice there is an "official" boolean value in each event item) and create a string list containing each event "key" (the first value in each event item)
2) for each event "key", make a list of teams attending each event and sort each team by their "team_number"
Here is a test page for the event list. Here is the test page for the team list from one event.
My biggest problem with the JSON.NET library/documentation is that I can't seem to figure out how to take each item and isolate one specific value from it. For example, there are a whole bunch of values in each event item, but I only need the "official" value and the "key" value. Same with the teams, I only need the "team_number" value from each item.
Can you guys help me understand the library a little bit more or maybe even point me to the correct library if this is the wrong one for the job?
First thing to do is use json2csharp to generate the classes that represent your JSON.
public class Event
{
public string key { get; set; }
public string website { get; set; }
public bool official { get; set; }
public string end_date { get; set; }
public string name { get; set; }
public string short_name { get; set; }
public string facebook_eid { get; set; }
public string event_district_string { get; set; }
public string venue_address { get; set; }
public int? event_district { get; set; }
public string location { get; set; }
public string event_code { get; set; }
public int year { get; set; }
public List<object> webcast { get; set; }
public List<object> alliances { get; set; }
public string event_type_string { get; set; }
public string start_date { get; set; }
public int event_type { get; set; }
}
public class Team
{
public string website { get; set; }
public string name { get; set; }
public string locality { get; set; }
public int rookie_year { get; set; }
public string region { get; set; }
public int team_number { get; set; }
public string location { get; set; }
public string key { get; set; }
public string country_name { get; set; }
public string nickname { get; set; }
}
Now you can deserialize the JSON into lists of those objects and use LINQ to query what you need out of the list. I'm doing this from memory so it may need some tweaking to work.
var events = JsonConvert.Deserialize<IEnumerable<Event>>( eventJson );
var officialEvents = events.Where( e => e.official )
.Select( e => new { e.key, e.official } );
i am hanging for while and i dont understand one thing...I will try to explain my issue...
I have model(Table) called FeuerwehrPerson and the class looks like that:
public partial class FeuerwehrPerson
{
public FeuerwehrPerson()
{
this.BuchungenResultateList = new List<BuchungenResultate>();
this.Notenspiegel=new Notenspiegel();
this.Gemeinde=new Gemeinde();
}
public int FeuerwehrPersonId { get; set; }
public string Anrede { get; set; }
public string Vorname { get; set; }
public string Nachname { get; set; }
public System.DateTime Geburtstag { get; set; }
public string Strasse { get; set; }
public string Plz { get; set; }
public string Ort { get; set; }
public string Telefon { get; set; }
public int GemeindeId { get; set; }
public Nullable<int> NotenspielgelId { get; set; }
public virtual ICollection<BuchungenResultate> BuchungenResultateList { get; set; }
public virtual Gemeinde Gemeinde { get; set; }
public virtual Notenspiegel Notenspiegel { get; set; }
}
In Feuerwehrperson are 2 Foreign Keys
GemeindeId
NotenspiegelId
and both of them are holding some values for a specific FeuerwehrPerson.
Both Foreign Keys are not null in my FeuerehrPerson Table...
In my Controller i have a Edit Action...and i am searching for FeuerwehrPerson by id...thats working fine:
FeuerwehrPerson feuerwehrperson = db.FeuerwehrPerson.Find(id);
When i am checking the values by using add Watch of feuerwehrperson Object there are some empty properties which shouldn´t be empty
The Object property Gemeinde should contain some values but its empty...also for Notenspiegel Object should contain SeminarA=true, SeminarB=true, SeminarC=true, rest is false but everything is false also NotenspiegelId and GemeindeId...but the Foreign Key references in Feuerwehrperson are not null...but why is it empty????
Please help me...
I want to update a table row and I have a following Code
void updatePrimaryPaymentAndSecondaryPaymentSourceTypes()
{
LookUpDetails lookUpDetail = new LookUpDetails();
var repo = new SimpleRepository("E2Lending", SimpleRepositoryOptions.RunMigrations);
lookUpDetail = repo.Single(80);
lookUpDetail.Col1Value = "My Checking Account";
repo.Update(lookUpDetail);
}
public class LookUpDetails
{
[SubSonicPrimaryKey]
public int LookUpDetailId {get; set;}
public int LookUpGroupId { get; set; }
public string Code { get; set; }
public int SortOrder { get; set; }
public string Col1Value { get; set; }
[SubSonicNullString]
public string Col2Value { get; set; }
[SubSonicNullString]
public string Col3Value { get; set; }
[SubSonicNullString]
public string Col4Value { get; set; }
[SubSonicNullString]
public string Col5Value { get; set; }
public DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; }
public DateTime ModifiedOn { get; set; }
public string ModifiedBy { get; set; }
public Boolean IsActive { get; set; }
}
When I execute then repo.Update(lookUpDetail); shows me Null reference Exception.
Can you please tell me How I will be able to update a single record in a table?
Regards
I have the very same problem with very simple model class:
class Person
{
public long ID {get;set;}
public string Name { get; set;}
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection) {
Person toUpdate = Repository.All<Person>().Single(p => p.ID == id);
TryUpdateModel(toUpdate, collection.ToValueProvider());
Repository.Update(toUpdate); //throws nullreferenceexception
return RedirectToAction("Index");
}
stack trace:
at SubSonic.Query.Update.GetCommand()
at SubSonic.Query.Update.Execute()
at SubSonic.Repository.SimpleRepository.Update[T](T item)
at MvcApplication1.Controllers.PersonController.Edit(Int32 id, FormCollection collection)
in H:\...\Controllers\PersonController.cs:line 71"
My configuration: SubSonic 3, SQLite, empty database
I ran into this problem as well and I was able to download the latest SubSonic source and the issue was already fixed. Just open the SubSonic.Core project and do a build and replace your project's reference to SubSonic.Core.
Download Latest Source
http://github.com/subsonic/SubSonic-3.0
Boom - Repository Update works again!