0

I'm starting working with the Entity Framework 6 and got a problem with dynamic models. I have the following model:

public class EF6
{
    public Guid Guid { get; set; }
    public int Int2 { get; set; }
    public string Str { get; set; }
    public byte[] Doc { get; set; }
}

Which is added to the context like this:

Entities ent = new Entities();
var dbSet = ent.Set<EF6>();

EF6 e = new EF6();
e.Guid = Guid.NewGuid();
e.Int2 = 123;
e.Str = "Hello World";
e.Doc = new byte[1] { 0 };

dbSet.Add(e);

But on the dbSet.Add(e) part, i get the following error: The entity type EF6 is not part of the model for the current context.

Does any one has an solution for this problem?

EDIT

Later i want to write some of my models in IronPython and add them over dbSet.Add.

EDIT 2

enter image description here

BendEg
  • 20,098
  • 17
  • 57
  • 131

1 Answers1

0
 testEntities entityt = new testEntities();
        var dbset = entityt.Set<TestTable>();

        TestTable TT = new TestTable();
        TT.City = "AHD";
        TT.Name = "Ajay";
        TT.Nr = "1236578";
        dbset.Add(TT);

        entityt.SaveChanges();

This is working for me.

Ajay
  • 444
  • 2
  • 9
  • Thank you for your answer, in my case (look at the picture) it did not work. – BendEg Feb 25 '15 at 11:41
  • Are you sure that the class EF6 is part of your edmx ? Check again. because I have tried to replicate this error and I am successful to get this error. My class is not part of edmx and I got this error. – Ajay Feb 25 '15 at 12:00
  • No, it is not part of the edmx, because i've added the model "dynamically". Can i add a model dynamically to the edmx? – BendEg Feb 25 '15 at 13:02
  • then you have to go for Code first approach. – Ajay Feb 25 '15 at 13:03
  • I don't get you what you exactly want. if you have table in DB then why do you need to create dynamically ? You have to Map your model to edmx for successful operation – Ajay Feb 25 '15 at 13:52
  • For example, i have one DB context, and my models are seperated in different assemblies. So i have an existing database with all tables in it. But not all tables are loaded into the designer. (edmx). – BendEg Feb 25 '15 at 14:01