asp.net - Photos and Database -


I am working on a website, where users can upload photos of the advertisement's product. I am saving photos in a folder on the Web in the table where I refer to the photo, there is an important field photo, which is the identity field (primary key).

The following methods are in my repository

  photo photo = rep.NewPhoto (); Photo.Title = "Some Title"; Rep.InsertPhoto (photo); Rep.SaveAll (); Rep.SavePhoto (photo, uploadedPhoto); Rep.SaveAll ();  

I am using SQL from my Linq for data model. Now my problem is, if I want to save my file by name which is coming from Photo ID, then I will have to call rep.SaveAll () method to get a newly created photo and then upload the photo I have to save with ID and then I have to change it in the SavePhoto () method, to call it SaveAll () method to update it again.

The other option is to save the file first with some random file number and then save the photo record in one step

This is the second approach.

  Photo photo = representative. Newfoto (); Photo.Title = "Some Title"; String file name = Rep. SavePhoto (Uploaded photo); Photo.FileName = file name; Rep.InsertPhoto (photo); Rep.SaveAll ();  

Saving the file with the photoded is a good thing, photos can be easily loaded using your ID.

Text ">

The second approach is definitely more efficient; Other options may be to make a unique one in your application layer (you can use grids) and then use it as a key DB record and file name.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -