2

I'm using Entity Framework 5 and using the code-first model. I'm trying to create a model that represents a PDF and some associated data fields. For example:

Receipt
---------
Id
Date
Retailer
Total
FilePath

I recently transitioned from a role working with Django. Django's ORM allows me to easily add a file field type and it will store the path in the database and the file in the file system. It seems like EF can be manually coded around to do something like that according to File Upload ASP.NET MVC 3.0. I built a prototype based on this artice, but it seems like a waste of time to add this code to each create and update action in controllers.

I'm assuming there's another way to easily model this and I just haven't found it in the docs. I'm even willing to consider something that sticks the file into the database itself for now. I just want something I can do quickly and not have to add a bunch of bolier plate type code when auto generating the views and controllers based on the model. I have several of these tables that model a file and specific additional data.

*Note - This is for a prototype. Something unlikely to see production in it's current form.

Community
  • 1
  • 1
RyanBrady
  • 6,633
  • 4
  • 27
  • 32
  • I was going to say `DataAnnotation`s, but it turns out you can't use them for this purpose - see http://stackoverflow.com/questions/9891040/asp-net-mvc-3-viewmodel-data-annotations. There was some possible solutions towards the bottom of that page. – Aaron Newton Dec 12 '12 at 01:12
  • I didn't see anything on that link remotely similar to what I'm asking. – RyanBrady Dec 12 '12 at 15:52
  • Sorry, that's because it was the WRONG LINK (sorry about that - too many SO windows open at once). Try this one http://stackoverflow.com/questions/6285624/how-to-validate-input-file-with-jquery-and-dataannotation-in-asp-net-mvc-3. In retrospect this is more about validating a file on upload, so I'm not sure that it answers your question. – Aaron Newton Dec 12 '12 at 21:22

0 Answers0