Click here to Skip to main content
15,502,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I'm doing my final project. I have to use Bridge Design Pattern with Entity Framework but I'm not sure how can I use these two and how can I do CRUD operations?

I'm implementing IDatamanagment interface to StudentData class.

My code goes like this:

C#
 namespace BusinessLayer
{
   public class StudentData:IDataManagement<Ogrenci>
  {
        private List<Ogrenci> ogrenci = null;
        public int kimlikno { get; set; }
        public string ad { get; set; }
        public string soyad { get; set; }
        public DateTime dogumtarihi { get; set; }
        public string adres { get; set; }

        public void NextStudent()
        {
            if (kimlikno <= ogrenci.Count - 1)
            {
                kimlikno++;
            }
        }

        public void PriorStudent()
        {
            if (kimlikno > 0)
            {
                kimlikno--;
            }
        }

        public void AddStudent(Ogrenci t)
        {
            using (OgrenciDBEntities db = new OgrenciDBEntities())
            {
                db.Ogrenci.Add(new Ogrenci { Ad=ad, 
                    Soyad = soyad, 
                    DogumTarihi = Convert.ToDateTime(dogumtarihi), 
                    Adres = adres });
                db.SaveChanges();
            }
        }

        public void DeleteStudent(Ogrenci t)
        {
            if (kimlikno != 0)
            {
                using (OgrenciDBEntities db = new OgrenciDBEntities())
                {
                    Ogrenci ogr = db.Ogrenci.Where(o => o.KimlikNumarasi == kimlikno).FirstOrDefault();
                    db.Ogrenci.Remove(ogr);
                    db.SaveChanges();
                }
            }
        }

        public void ListStudent()
        {
            using (OgrenciDBEntities db = new OgrenciDBEntities())
            {
                var ogrenci = (from o in db.Ogrenci
                               select new
                               {
                                   kimlikno = o.KimlikNumarasi,
                                   ad = o.Ad,
                                   soyad = o.Soyad,
                                   dogumtarihi = o.DogumTarihi,
                                   adres = o.Adres
                               }
                                 ).ToList();
            }
        }

        public void UpdateStudent()
        {
            if (kimlikno != 0)
            {
                using (OgrenciDBEntities db = new OgrenciDBEntities())
                {
                    Ogrenci ogr = db.Ogrenci.Where(o => o.KimlikNumarasi == kimlikno).FirstOrDefault();
                    ogr.Ad = ad;
                    ogr.KimlikNumarasi = Convert.ToInt16(kimlikno);
                    ogr.Soyad = soyad;
                    ogr.DogumTarihi = dogumtarihi;
                    ogr.Adres = adres;
                    db.SaveChanges();
                }
            }
        }

    }
}

Any help would be appreciated, thanks in advance
Posted
Updated 21-Feb-16 23:33pm
Comments
Sergey Alexandrovich Kryukov 17-Jan-16 11:53am    
Have you, really? I mean, implementing a certain design pattern cannot be a goal. It could be one of the means to achieve some real goals. So, I would start with explanation what you want to achieve.
—SA
Dilara_Neslisah 17-Jan-16 11:59am    
My goal is, how can i use bridge pattern with entity framework in a project?

thanks
Sergey Alexandrovich Kryukov 17-Jan-16 12:14pm    
I already heard that. As I say, it cannot be a real goal. What would be the ultimate goal of all this activity?
—SA
Dilara_Neslisah 17-Jan-16 12:35pm    
Actually I'm computer programming student, this is my graduate thesis. I should make CRUD operations from existing database by using bridge pattern.
Sergey Alexandrovich Kryukov 17-Jan-16 13:00pm    
Is your final project? Is your school's final project something where not you makes the decisions on the techniques to use, but someone else?
—SA

1 solution

You should use Repository or Unit of Work design pattern with Entity Framework.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900