-1

I have a problem with EF and a table that has only one identity column: The table is FileData and the column is id_file_data that is an identity column (mysql database) and I have this code for the creation:

EntitiesContext context = new EntitiesContext();
FileData fileData = new FileData();
context.FileDatas.AddObject(fileData);
try
{
    context.SaveChanges();
}catch(Exception ex)
{
    throw ex;
}

But on the context.SaveChanges() I have a null reference exception. What do I have to do to insert this entity?

Thanks!

PowerStat
  • 3,757
  • 8
  • 32
  • 57
Phoenix_uy
  • 3,173
  • 9
  • 53
  • 100
  • Probably MySql-specific. No problem with Sql server 2008 (+ EF 4.3). Is the column defined as primary key? But... is this worth the effort? Is there any practical use for a table with an id column only? – Gert Arnold Feb 28 '12 at 09:46
  • @GertArnold thanks for your answer. The column is defined as primary key, and the case of this is for a file management logic. I have different entities that can have a file manager or an image manager, so i put something like this in my logic: Entity has a foreign key to this one single column table, then i have two more tables called FileImage and FileDocument that have his own primary key, but also has a foreign key to this single column table (called FileData). With this logic, my entity has only one FileData id, but this id, has many FileDocument's and FileImage's. – Phoenix_uy Feb 29 '12 at 11:55
  • 1
    OK, like a polymorphic association, [I could have known...](http://stackoverflow.com/questions/8895806/how-to-implement-polymorphic-associations-in-an-existing-database). Well I hope you'll get it sorted out with MySql. Maybe a second column (e.g. an entity code) would do the trick. – Gert Arnold Feb 29 '12 at 12:25
  • Yes @GertArnold, that's what i did.. i add a second (garbage column) tiny int called isActive.. it really does nothing, but solve my EF problem :) – Phoenix_uy Feb 29 '12 at 12:42

0 Answers0