Bonjour,

J'essaie d'utiliser Entity Framework le problème que je rencontre et qu'après avoir contruit mon model il m'a bien construit les entités mais quand je veux insérer une instance de mon entité je n'arrive pas à lui faire remplir un champs je m'explique :
voici les entités qui sont le reflet de ma bd sauf le champ de liaison que l'on ne voit pas qui est Date_Evenement.


Voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
var bdd = new SupervisionEntities();
            Log_Supervision_Fichiers superfic = new Log_Supervision_Fichiers();
            superfic.Nom_Fichier =  e.Name ;
            superfic.Import= true;
            // Date_Evenement
            superfic.Date_Integration = DateTime.Now;
            var fichier = new System.IO.FileInfo(e.FullPath);
            superfic.Date_Creation = fichier.LastWriteTime;
            superfic.Export=false;
            superfic.Extension = fichier.Extension;
            bdd.AddToLog_Supervision_Fichiers(superfic);
            bdd.SaveChanges();
Le problème est que je veux insérer je ne sais pas comme remplir le date_evenement qui n'est pas disponible dans la complétion la seule chose que je vois c'est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
superfic.R_TEMPS.ID_DATE= DateTime.Now;
qui me renvoit une erreur sur cette ligne.
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Supervision_Fichiers_Vegas.Program.Main() in F:\VEGAS\DEV\Supervision_Fichiers_Vegas\Supervision_Fichiers_Vegas\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.NullReferenceException
Message="Object reference not set to an instance of an object."
Source="Supervision_Fichiers_Vegas"
StackTrace:
at Supervision_Fichiers_Vegas.F_Supervision.mySysFileWatcher_Created(Object sender, FileSystemEventArgs e) in F:\VEGAS\DEV\Supervision_Fichiers_Vegas\Supervision_Fichiers_Vegas\F_Supervision.cs:line 31
InnerException:
Merci de votre aide