'How to map SQL Server vertical data into Entity Framework class and then to Angular page
I'm new to this forum, and I have only few experience using Entity Framework.
I hope to post a clear issue: I have already implemented classes, API and SPA page to show stock technical properties. Initially, all the fields were strings or numbers, without any kind of check of the correctness of the values (I have inherited dirty data from an old database). Some of the string fields need to be normalized, reading data from a "clean" list. I tried to extract the different values from the original (dirty) table, in order to create a lookup table.
Due to I have different fields with the same data type, I figured out to develop a vertical table as follows:
Id CategoryName CategoryMake CategoryType
...
10 Engine Mercedes OM926LA T4i
11 Engine Mercedes OM934LA T4f
12 Engine Mercedes OM936LA T4f
13 Engine Perkins SERIE 700
14 Engine Volvo TAD1183 VE St.5
15 Engine Volvo TAD720 VE
16 Engine Volvo TAD750 VE
17 Engine Volvo TAD870 VE T4f
...
25 EngineECU Mercedes OM906LA.111/2-00
26 EngineECU Mercedes OM926LA.E3B/5-01
27 EngineECU Mercedes OM934LAE4-3-01
28 EngineECU Volvo TAD870 VE T4f
29 EngineECU Volvo TAD871 VE T4f
30 EngineECU Volvo TAD872 VE T4f
31 FirstAxle AxleTech 5511SFW8661
32 FirstAxle AxleTech 5511SFW8662
33 FirstAxle AxleTech A87213661
34 FirstAxle AxleTech A87213662
35 FirstAxle Kessler D81PL478NLB5340
In the web page, I need to put, for each CategoryName, a list of distinct CategoryMake, and for each CategoryName + CategoryMake, the list of CategoryType, using mat-autocomplete fields.
My issue is that I need to convert all these fields from strings to complex structures containing CategoryName, CategoryMake and CategoryType, but I'm having errors on API retrieval methods.
ADDITIONAL INFO: Each CategoryName represents a block of info (Engine data, First Axle data and so on). Each CategoryMake represents the brand of the piece (the Engine can be Mercedes, Volvo, Perkins, etc.). Each CategoryType represents the model of the piece.
I've tried to follow another structure that actually works, but based on a lookup table with only two fields (code and description). The search key is the code (CatMercCode) and the object that references the table is defined in a CatMercResource class:
public class StockItemResource
{
public int Id { get; set; }
public int? StockId { get; set; }
public string CatMercCode { get; set; }
public CatMercResource CatMerc { get; set; }
}
In my class I tried this definition for the field called "GeneralType", represented in the lookup table as:
Id CategoryName CategoryMake CategoryType
292 General Type
293 General Type BC182
294 General Type BC182 4x2
295 General Type MG5032
296 General Type ML1812R
297 General Type RT222
298 General Type RT223
299 General Type RT282
300 General Type RT283
301 General Type RT323
302 General Type RT403
303 General Type STACKACE-E7-9
304 General Type TT223
305 General Type TT223 CC
306 General Type TT2516
307 General Type YT182
308 General Type YT182 4x2
309 General Type YT193
310 General Type YT203EV
311 General Type YT222
312 General Type YT222 4X2
313 General Type YT223
314 General Type YT282
And my class:
public class StockTechnicalInfoResource
{
public string GeneralName { get; set; }
public string GeneralMake { get; set; }
public StockTechnicalInfoTypeResource GeneralType { get; set; }
//public DateTime? GeneralDeliveryDate { get; set; }
public double? GeneralWheelBase { get; set; }
public double? GeneralWeightFront { get; set; }
public double? GeneralWeightRear { get; set; }
public string EngineMake { get; set; }
public StockTechnicalInfoTypeResource EngineType { get; set; }
public string EngineSerialNumber { get; set; }
public string EngineWarrantyPeriod { get; set; }
public string EngineECUMake { get; set; }
public StockTechnicalInfoTypeResource EngineECUType { get; set; }
public string EngineECUPartNumber { get; set; }
public string EngineECUSerialNumber { get; set; }
public double? GeneralWeightTotal { get; set; }
...
}
In any way I'd need to read from the same table columns and put values on different properties. I hope to explain myself, even if I'm afraid that is too complex to be explained in this way...
Could anyone suggest me any idea? Many thanks in advance!
Best regards,
Laura
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
