IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Accès aux données Discussion :

[EF] Ajouter une entité


Sujet :

Accès aux données

  1. #1
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut [EF] Ajouter une entité
    Salut a tous ,
    j'ai un petit probleme que j'arrive pas a le resoudre .
    je suis sur un projet Silverlight , j'utilise ADO.NET EDM et LinqToEntity pour l'acces aux donnees , le probleme j'arrive pas a ajouter une entité .
    voila le code que j'utilise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    dbEntities db = new dbEntities();
    var ev = new TABLE { ID = "10", TITRE = "blabla", DATE = DateTime.Now};
    db.AddToTABLE(ev);
    db.SaveChanges();
    et cela me genere une erreur au niveau de db.SaveChanges()
    Impossible de mettre à jour l'EntitySet « TABLE » parce qu'il comprend un DefiningQuery et qu'il n'existe dans l'élément <ModificationFunctionMapping> aucun élément <InsertFunction> pour la prise en charge l'opération actuelle.
    quelqu'un pourrait m'aider ??
    merci d'avance

  2. #2
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    voila ma classe généré si ça peut aider :
    le nom de la BDD "SOUKDB" , la table "EVENT (ID,TITRE,DATE,TEXTE)" :
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    [assembly: global::System.Data.Objects.DataClasses.EdmSchemaAttribute()]
     
    // Nom du fichier d'origine*:
    // Date de génération*: 10/03/2009 13:31:06
    namespace SOUK_SBA
    {
     
        /// <summary>
        /// Il n'existe aucun commentaire pour SOUKDBEntities1 dans le schéma.
        /// </summary>
        public partial class SOUKDBEntities1 : global::System.Data.Objects.ObjectContext
        {
            /// <summary>
            /// Initialise un nouvel objet SOUKDBEntities1 à l'aide de la chaîne de connexion trouvée dans la section «*SOUKDBEntities1*» du fichier de configuration d'application.
            /// </summary>
            public SOUKDBEntities1() : 
                    base("name=SOUKDBEntities1", "SOUKDBEntities1")
            {
                this.OnContextCreated();
            }
            /// <summary>
            /// Initialise un nouvel objet SOUKDBEntities1.
            /// </summary>
            public SOUKDBEntities1(string connectionString) : 
                    base(connectionString, "SOUKDBEntities1")
            {
                this.OnContextCreated();
            }
            /// <summary>
            /// Initialise un nouvel objet SOUKDBEntities1.
            /// </summary>
            public SOUKDBEntities1(global::System.Data.EntityClient.EntityConnection connection) : 
                    base(connection, "SOUKDBEntities1")
            {
                this.OnContextCreated();
            }
            partial void OnContextCreated();
            /// <summary>
            /// Il n'existe aucun commentaire pour EVENT dans le schéma.
            /// </summary>
            public global::System.Data.Objects.ObjectQuery<EVENT> EVENT
            {
                get
                {
                    if ((this._EVENT == null))
                    {
                        this._EVENT = base.CreateQuery<EVENT>("[EVENT]");
                    }
                    return this._EVENT;
                }
            }
            private global::System.Data.Objects.ObjectQuery<EVENT> _EVENT;
            /// <summary>
            /// Il n'existe aucun commentaire pour EVENT dans le schéma.
            /// </summary>
            public void AddToEVENT(EVENT eVENT)
            {
                base.AddObject("EVENT", eVENT);
            }
        }
        /// <summary>
        /// Il n'existe aucun commentaire pour SOUKDBModel.EVENT dans le schéma.
        /// </summary>
        /// <KeyProperties>
        /// ID
        /// </KeyProperties>
        [global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="SOUKDBModel", Name="EVENT")]
        [global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]
        [global::System.Serializable()]
        public partial class EVENT : global::System.Data.Objects.DataClasses.EntityObject
        {
            /// <summary>
            /// Créez un nouvel objet EVENT.
            /// </summary>
            /// <param name="id">Valeur initiale de ID.</param>
            public static EVENT CreateEVENT(string id)
            {
                EVENT eVENT = new EVENT();
                eVENT.ID = id;
                return eVENT;
            }
            /// <summary>
            /// Il n'existe aucun commentaire pour la propriété ID dans le schéma.
            /// </summary>
            [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
            [global::System.Runtime.Serialization.DataMemberAttribute()]
            public string ID
            {
                get
                {
                    return this._ID;
                }
                set
                {
                    this.OnIDChanging(value);
                    this.ReportPropertyChanging("ID");
                    this._ID = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, false);
                    this.ReportPropertyChanged("ID");
                    this.OnIDChanged();
                }
            }
            private string _ID;
            partial void OnIDChanging(string value);
            partial void OnIDChanged();
            /// <summary>
            /// Il n'existe aucun commentaire pour la propriété TITRE dans le schéma.
            /// </summary>
            [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
            [global::System.Runtime.Serialization.DataMemberAttribute()]
            public string TITRE
            {
                get
                {
                    return this._TITRE;
                }
                set
                {
                    this.OnTITREChanging(value);
                    this.ReportPropertyChanging("TITRE");
                    this._TITRE = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
                    this.ReportPropertyChanged("TITRE");
                    this.OnTITREChanged();
                }
            }
            private string _TITRE;
            partial void OnTITREChanging(string value);
            partial void OnTITREChanged();
            /// <summary>
            /// Il n'existe aucun commentaire pour la propriété DATE dans le schéma.
            /// </summary>
            [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
            [global::System.Runtime.Serialization.DataMemberAttribute()]
            public global::System.Nullable<global::System.DateTime> DATE
            {
                get
                {
                    return this._DATE;
                }
                set
                {
                    this.OnDATEChanging(value);
                    this.ReportPropertyChanging("DATE");
                    this._DATE = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
                    this.ReportPropertyChanged("DATE");
                    this.OnDATEChanged();
                }
            }
            private global::System.Nullable<global::System.DateTime> _DATE;
            partial void OnDATEChanging(global::System.Nullable<global::System.DateTime> value);
            partial void OnDATEChanged();
            /// <summary>
            /// Il n'existe aucun commentaire pour la propriété TEXTE dans le schéma.
            /// </summary>
            [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
            [global::System.Runtime.Serialization.DataMemberAttribute()]
            public string TEXTE
            {
                get
                {
                    return this._TEXTE;
                }
                set
                {
                    this.OnTEXTEChanging(value);
                    this.ReportPropertyChanging("TEXTE");
                    this._TEXTE = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
                    this.ReportPropertyChanged("TEXTE");
                    this.OnTEXTEChanged();
                }
            }
            private string _TEXTE;
            partial void OnTEXTEChanging(string value);
            partial void OnTEXTEChanged();
        }
    }

  3. #3
    Futur Membre du Club
    Inscrit en
    Février 2009
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 15
    Points : 7
    Points
    7
    Par défaut
    Assure-toi d'avoir correctement affecté tous les champs "NOT NULL" ainsi que l'(les) entité(s) étrangère(s) liée(s) à ton nouvel objet

    Pour vérifier si ta nouvelle donnée est "valide" pour être rentrée dans la base, essaye d'abord de l'ajouter en dur directement dans la BDD sans passer par du code C# (avec SQL Server par exemple )

    Sinon si la clé primaire de ton nouvel objet est incrémentée automatiquement, pas besoin de l'affectée ! Si elle est unique mais saisie à la main, assure-toi qu'elle n'est pas déjà utilisée

  4. #4
    Membre averti Avatar de bellak
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juillet 2008
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Juillet 2008
    Messages : 325
    Points : 341
    Points
    341
    Par défaut
    Salut , pardon pour ce retard
    mon problème est résolu, l'erreur été dans ma BDD j'ai pas défini la clé primaire .
    merci h0pelessS

  5. #5
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Février 2011
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2011
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    Merci d'être venu pour donner la solution !
    C'est tout bête mais on peut perdre beaucoup de temps à chercher pourquoi ça marche pas...

  6. #6
    Nouveau membre du Club
    Profil pro
    Développeur décisionnel
    Inscrit en
    Avril 2008
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur décisionnel
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Avril 2008
    Messages : 17
    Points : 25
    Points
    25
    Par défaut BDD
    Merci bellak pour ta réponse

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Ajouter une entité dans deux tables
    Par jeyGey dans le forum Doctrine2
    Réponses: 0
    Dernier message: 07/03/2013, 11h18
  2. Réponses: 2
    Dernier message: 18/11/2010, 13h00
  3. Réponses: 4
    Dernier message: 26/08/2009, 15h36
  4. Réponses: 1
    Dernier message: 23/08/2009, 14h55
  5. ajouter une colonne a une entité qui ne sera pas mappé
    Par *alexandre* dans le forum Hibernate
    Réponses: 3
    Dernier message: 02/10/2008, 09h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo