samedi 1 août 2015

Using two versions of entity framework in the same solution

I have a webApi application in which I used EF6 in the web project and EF5 in the DAL layer.

I have this method in the crud class( in DAL) :

 public bool Delete(params T[] items)
    {
        if (context == null) context = GetContext();
        try
        {
            foreach (T item in items)
            {
                context.Entry(item).State = System.Data.EntityState.Deleted;
            }
            context.SaveChanges();
            return true;
        }
        catch
        {
            return false;
        }


    }

in the BLL I made this call :

 public void UpdatePhoto(string id, byte[] image)
   {
       if (cruder == null) cruder = new Crud<ajt_photo>();
       List<ajt_photo> lstphoto = cruder.GetAll().ToList();
       ajt_photo photo = lstphoto.Where(x => x.id_user_fk == id).FirstOrDefault();
       if (photo != null) cruder.Delete(photo);
       ajt_photo pho = new ajt_photo() { id_user_fk = id, image = image };
       cruder.AddNew(pho); 
   }

I get a weird exception :

enter image description here

It indicates that the method is not found !!! I think it is because of entity framework version in this line :

EF5

context.Entry(item).State = System.Data.EntityState.Deleted;

EF6

context.Entry(item).State = System.Data.Entity.EntityState.Deleted;

So I need to know :

  1. How can I fix this problem?

Aucun commentaire:

Enregistrer un commentaire