2016-07-22 36 views
0

Ich erzeuge meine Klassen mit Linq zu Sql, und ich habe eine Spalte "DataValue", die eine sql_variant ist.Wie Werte aus einer Spalte sql_variant mit LINQ TO SQL (ASP.NET) angezeigt werden?

MODEL

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DataValue", DbType="Variant", UpdateCheck=UpdateCheck.Never)] 
     public object DataValue 
     { 
      get 
      { 
       return this._DataValue; 
      } 

REGLER:

public ActionResult getDataForAPlc() 
     { 
      int plc = 1; 
      var dataContext = new PLCDataContext(); 
      var datas = from tag in dataContext.PLC_Data_5m 
          where tag.TagID == plc && tag.TimeStampLocal >= new DateTime(2016, 7, 20) && tag.TimeStampLocal < new DateTime(2016,7,21) 
          orderby tag.TimeStampLocal descending 
          select tag; 
      return View(datas); 
     } 

und ich nutzte die Ansicht GENERATOR (Razor) Zu meiner Liste des Wertes von meinem QUERY zu erzeugen.

Problem: Ich sehe alle Werte, außer Datavalue. Es gibt nichts, und wenn ich die Ansicht erzeuge, wird DataValue standardmäßig nicht angezeigt. Ich habe es auf meinem View.cshtml hinzugefügt

@model IEnumerable<DataReports.Models.PLC_Data_5m> 

@{ 
    ViewBag.Title = "getDataForAPlc"; 
} 

<h2>getDataForAPlc</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table class="table"> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.TimeStampLocal) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.DataTimeStamp) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.DataQuality) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.DataValue) 
     </th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.TimeStampLocal) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.DataTimeStamp) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.DataQuality) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.DataValue) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | 
      @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) 
     </td> 
    </tr> 
} 

Und es gibt keine Werte. Kann mir jemand helfen? Ich weiß, das ist eine Objekteigenschaft wegen sql_variant, aber, wie man einen Wert davon erhält?

Antwort