Click here to Skip to main content
15,117,719 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
Dilara_Neslisah 17-Jan-16 13:29pm
   
Unfortunately, he gave this project.

In your opinion could it be possible?
Sergey Alexandrovich Kryukov 17-Jan-16 13:34pm
   
Sorry. This is not about possible or impossible. This is about understanding of purposes of projects and techniques. About what makes sense and what not. You have been given a project. But have you been given requirements? Do they include the techniques you have to use? Anyway, this is not how I understand education.
—SA
Dilara_Neslisah 17-Jan-16 13:50pm
   
No problem, we can't understand too.
Ok, this is the documantation of my project:

Project subjects;
1- Bridge Design Pattern
2- N-tier Architecture
3- Entity Framework

Create a student informations database. Make CRUD operations by using N-tier architecture and bridge design pattern.
Sergey Alexandrovich Kryukov 17-Jan-16 14:12pm
   
Okay, I got it. At this moment, I've lost my interest. I'm sorry; please understand me.
This is not how a project subject should be formulated. It could be a set of topics for a school course, but not a project which should be result in a software product. And it is not adequate to the idea of final school project. Sorry, but it makes me doubtful about your school; I'm not sure it really provides consistent education.
Sorry again.
—SA
Dilara_Neslisah 17-Jan-16 14:19pm
   
Thanks for your help and opinions.
Sergey Alexandrovich Kryukov 17-Jan-16 14:31pm
   
You are very welcome. Sorry that you did not get help; I really don't see much sense in this assignment.

However, I would advise just to learn this particular pattern, as well as other patterns. The patters are useful not as goals or requirements. First, you should think at the design of your application according to the goals of that application. You never shared those goals. And when you look for the solutions, you may think: "what other people did in similar situations". And then you can look at the well-known pattern, not just one, many of them. And think if one or more can be useful for you. And only then you decide to use one or more of them, or create your own solution, which may or may not become a pattern. It you approach to it upside down, starting from a pattern, you are not approaching your project goals.

—SA
Dilara_Neslisah 17-Jan-16 15:34pm
   
Okay, I will apply your advices. thank you for allow time to my question
Sergey Alexandrovich Kryukov 17-Jan-16 20:09pm
   
You are very welcome.
—SA

1 solution

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

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