Quantcast
Channel: Visual Basic Tips and Tricks
Viewing all articles
Browse latest Browse all 2212

[vb2015] Partial Class di Entity Framework

$
0
0

Salve a tutti ragazzi volevo chiedervi delle informazioni circa un operazione che non riesco ad eseguire.

Vi illustro lo scenario

ho un database Mysql con la tabella Prev e la tabella preventivi_computo_metrico

per ogni voce del computo metrico c'è il tempo di posa in opera.

Ora caricando i dati con entity framework per poter ottenere per ogni preventivo il tempo di posa in opera complessivo ho aggiunto delle proprietà alla Patrial Class Prev con il seguente codice

 

 

Partial Class Prev    Public ReadOnly Property TPO As Double        Get            Dim tempo As Double = 0            For Each cm In Me.prev_computo_metrico                Dim giorni As Double                Dim ore As Double                Dim minuti As Double                Dim secondi As Double                giorni = cm.tempo_posa_opera.Substring(0, 5)                ore = cm.tempo_posa_opera.Substring(7, 2)                minuti = cm.tempo_posa_opera.Substring(10, 2)                secondi = cm.tempo_posa_opera.Substring(13, 2)                Dim tempocm As Double = (giorni * 8 * 60 * 60) + (ore * 60 * 60) + (minuti * 60) + secondi                tempo = tempo + tempocm            Next            Return tempo        End Get    End Property    Public ReadOnly Property Tempo_Posa As String        Get            Dim tempo As String = ""            Dim secondi = TimeSpan.FromSeconds(Me.TPO)            Dim sec = secondi.Seconds            Dim min = secondi.Minutes            Dim gesthd = Me.TPO - sec - (min * 60)            Dim tmpore = gesthd / 60 / 60            Dim giorni = Fix(tmpore / 8)            Dim ore = (tmpore - giorni) * 8            tempo = String.Format("{0:00000}:{1:00}:{2:00}:{3:00}", giorni, ore, min, sec)            Return tempo        End Get    End PropertyEnd Class

faccio un test per vederne il funzionamento ed eseguo il seguente codice:

 

PrevContext = New EntitiesDim query = From p In PrevContext.prevs Where p.prev_id = "P2016-00109" Select pDim preventivo = query.SingleMessageBox.Show(preventivo.prev_computo_metrico.Count.ToString + "  tempo totale " + preventivo.TPO)

ma all'esecuzione della query mi da il seguente errore

 

 System.Data.Entity.Core.MetadataException non è stata gestita dal codice utente
  HResult=-2146232007
  Message=Schema specificato non valido. Errori:
La relazione 'PreventiviGareModel.prevprev_computo_metrico' non è stata caricata perché il tipo 'PreventiviGareModel.prev' non è disponibile.

  Source=EntityFramework
  StackTrace:
       in System.Data.Entity.Core.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
       in System.Data.Entity.Core.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
       in System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage)
       in System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly, Action`1 logLoadMessage)
       in System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly)
       in System.Data.Entity.Core.Metadata.Edm.MetadataOptimization.TryUpdateEntitySetMappingsForType(Type entityType)
       in System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
       in System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)
       in System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       in System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       in System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
       in System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
       in System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
       in WpfUC_TempoPOPrevGare.UC_ControlloTPOPreventivi.UC_ControlloTPOPreventivi_IsVisibleChanged(Object sender, DependencyPropertyChangedEventArgs e) in E:\ProgrammazioneODBC\PimmExtended\WpfUC_TempoPOPrevGare\UC_ControlloTPOPreventivi.xaml.vb:riga 23
       in System.Windows.UIElement.RaiseDependencyPropertyChanged(EventPrivateKey key, DependencyPropertyChangedEventArgs args)
       in System.Windows.UIElement.OnIsVisibleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       in System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       in System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
       in System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       in System.Windows.UIElement.UpdateIsVisibleCache()
       in System.Windows.UIElement.OnVisualParentChanged(DependencyObject oldParent)
       in System.Windows.Media.Visual.FireOnVisualParentChanged(DependencyObject oldParent)
       in System.Windows.Media.Visual.AddVisualChild(Visual child)
       in System.Windows.FrameworkElement.set_TemplateChild(UIElement value)
       in System.Windows.Controls.ContentPresenter.UseContentTemplate.BuildVisualTree(FrameworkElement container)
       in System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
       in System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
       in System.Windows.FrameworkElement.ApplyTemplate()
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
       in System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
       in System.Windows.Controls.Grid.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Border.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Control.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
       in System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Border.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Border.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Border.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Border.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.Controls.Control.MeasureOverride(Size constraint)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in Infragistics.Windows.DockManager.SplitPane.MeasureOverride(Size availableSize)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in Infragistics.Windows.DockManager.SplitPane.MeasureOverride(Size availableSize)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in Infragistics.Windows.DockManager.DocumentContentHostPanel.MeasureOverride(Size availableSize)
       in System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       in System.Windows.UIElement.Measure(Size availableSize)
       in System.Windows.ContextLayoutManager.UpdateLayout()
       in System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
       in System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       in System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       in System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       in System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       in System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
  InnerException:

 

 Mi da l'impressione che il problema sia dato dal fatto che cerca di calcolare i nuovi campi aggiunti da me prima ancora di aver caricato tutti i dati del database.

 

Qualcuno di voi potrebbe darmi qualche indicazioni in merito?

Vi ringrazio anticipatamente per i vostro aiuto.

 

 

 


Viewing all articles
Browse latest Browse all 2212