c# - View with multiple tables -


I have two tables in my database that are similar data but not the same.

I like finding the tables in the same view to search in the Internet is the most recommended way to use a Vuododal class.

So ... this is my class array:

iCareIndoorAlert.cs <[Table ("IKEAR Indoor Alerts")] Public Class ICare Indoor Alert {[Key] [DisplayName ("ID Alarm eKair Indoor")] Public Long Alert Id {Received; Set; } [DisplayName ("ID Messaggio")] Received Public Long MessageID {}; Set; } Public string UUID {get; Set; } Receive public ANIg; Set; } Public area MIN {get; Set; } [DisplayName ("Displacement")] Public Name District {Received; Set; } [DisplayName ("Data Jigsaw")] Public Date Time Date Time {Received; Set; } Public Virtual HTTPPP33TPTP 3 {Received; Set; } {Table ("iCareOutdoorAlerts")} Public class iCareOutdoorAlert {[Key] [DisplayName ("ID Allarme iCare Outdoors")] Received public long alert id { Set; } [DisplayName ("ID Messaggio")] Received Public Long MessageID {}; Set; } [DisplayName ("Letitudin")] received the public float wave; Set; } [DisplayName ("Longittidine")] Received Public Float Lawn; Set; } [DisplayName ("Purity")] Received Public Float ACC { Set; } [DisplayName ("Data Jigsaw")] Public Date Time Date Time {Received; Set; }}

Created a ViewModel folder with an iCareAlertViewModel.cs class:

Public listing & lt; ICareIndoorAlert & gt; {Get; ICareIndoorAlert; Set; } Public listing & lt; ICareOutdoorAlert & gt; {Receive ICareOutdoorAlert; Set; }

and added those rows to iCareEntities.cs:

  Public DbSet & lt; ICareIndoorAlert & gt; {Receive ICareIndoorAletters; Set; } Public DBSet & lt; ICareOutdoorAlert & gt; {Receive ICareOutdoorAletters; Set; } Public DbSet & lt; ICareAlertViewModel & gt; {Receive ICareAlertsViewModels; Set; }  

After I created iCareAlertController.cs and saw the index.cshtml but I get the "key not found" error, then in ViewModel I added a dummy variable with the [key] attribute And now I get an error that iCareAlertViewModel can not find the table ...

What am I doing wrong?

Thank you

First of all, do not create a dbet for your visual model, Which is not necessary. A visual model is one that sits between your data model (i.e. your entities) and your user interface.

What you probably need to do is define an interface that has the same properties for your two entities: something like this:

  Public Interface IAlert {Long AlertID { Get; Set; } Receive Long MessageID { Set; } // etc ...}  

Now each entity can implement that interface:

  public class iCareIndoorAlert: IAlert {// snip}  

Your view-model now:

  Public class warning Warning View MODEL: IALT {Public Received Long Alert Id {Receive; Set; } Receive Public Long MessageID { Set; } // snip}  

Then your view will now be something like this:

  @modelimimableable & lt; My.Assembly.AlertViewModel & gt; @foreach (Model in Vir Enter) {@ Html.DisplayFor (m = & gt; m.AlertID) // etc} Finally you can map your institutions to your visual model You can use the library manually, but it is something like this (including methodology and return):  
  Public Performance Index () {list & lt; IAlert & gt; Alert = GetOutdoorAlerts (); // list for example & lt; AlertViewModel & gt; AlertViewModels = Alert Select (a = & new; AlertViewModel {AlertID = a.AlertID, MessageID = a.MessageID, // etc ...}); See Return (Alert Viam Model); }  

Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

android - how to get distance of 2 beacons and make a condtion base on that distance -