1

How to tell the database to use Varbinary(max) for the image ?

I am using SQL Server Compact database with EF 6, and I can't open it from SQL Server 2008

public class Table
{
    public int Id { get; set; }
    public DateTime DateTime { get; set; }

    public byte[] Image { get; set; }

    [NotMapped]
    public string NotMapped { get; set; }
}

This exception happens to me when i try to save 300,000 byte image

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

HB MAAM
  • 3,913
  • 4
  • 29
  • 39

2 Answers2

0

I read the following SO Post by Ladislav and figured it would work out of the box. Does it not? I have not tried this personally.

Granted the article relates to EF Code First CTP5, but often CTPs are pretty close to final functionality.

How to store images using Entity Framework Code First CTP 5?

I use the following to easily see validation errors when debugging: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details

Community
  • 1
  • 1
CodeWarrior
  • 7,388
  • 7
  • 51
  • 78
  • i need to write some data type annotation in image property to tell EF to use that data type – HB MAAM Dec 07 '12 at 15:53
  • So, by default, with a property that is byte[] it will not receive data from a varbinary field? Does it give you an `EntityCommandExecutionException` saying the property "does not have a corresponding column in the data reader with the same name"? – CodeWarrior Dec 07 '12 at 15:58
  • Ahh. And what validation errors have you got? I normally get those for required properties or something like that. – CodeWarrior Dec 07 '12 at 16:04
  • Check my post above for link to a Stack Overflow article with a good exception handler that lets you get a look at the Validation Errors collection. – CodeWarrior Dec 07 '12 at 16:06
  • EntityValidationErrors -> Count = 1 – HB MAAM Dec 07 '12 at 16:06
  • Try using the exception handler in the first answer in that last link on my post above. It will output Validation errors to the console/output window. The validation error messages are generally pretty good at indicating where the real problem lies. – CodeWarrior Dec 07 '12 at 16:48
0

I am using SQL Server Compact database with EF 6, and I can't open it from SQL Server 2008

As far as I know, SQL Server Compact can not be managed through Management Studio. For this purposes you should use Server Explorer in Visual Studio (simple features only) or some outer software.

Illia Ratkevych
  • 3,507
  • 4
  • 29
  • 35
  • ok, nice, but still how to change the DB data type from EF or even give the byte[] a fixed length – HB MAAM Dec 08 '12 at 06:33
  • Try to use attribute. Something like [MaxLength(200)]. This works for string, but it also might help with byte. InteliSense will tell you possible options. Or try to use TypeName attribute. You should google for "EF model detalization" or "EF column attributes" for more precise answer. – Illia Ratkevych Dec 10 '12 at 10:51