EFDAL Wishlist

Mar 1, 2011 at 8:01 PM
Edited Mar 1, 2011 at 8:01 PM

Hi,

I am not sure if this is the place to put a wishlist.

I have to following Wishlist for the EFDAL:

  • Option to NOT generate the following statement in the Entity class: "[System.ComponentModel.DataAnnotations.MetadataType(typeof" and the associatet class "Metadata Class"
    Why ? When using i.e. the fluentvalidation module with MVC 3 (which uses UnobtrusiveJavaScriptEnabled) it gives some problems, because i.e. it is not allowed to use more then once the REQUIRED attribute.
  • Option to INLCUDE TypeAble / Immutable in the xxxxEntities.cs, when generate the libraries
  • generate the collections/reposotories and it's interfaces for the entities.

EXAMPLE of the Collections and it's interface

    public interface IPersoonCollection
    {
        IList<Persoon> RunSelect();
        IList<Persoon> RunSelect(string modifier);
        IList<Persoon> SelectAlleLeden();
        IList<Persoon> SelectAlleActieveLeden();

        IList<Persoon> SelectByAchternaam(string achternm);

        IList<Persoon> SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier);
        IList<Persoon> SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier);
        int NewLidNr();
        bool IsLidNrUnique(int lidnr, int id);
        //IQueryable<Persoon> FindBepByName(string q);
        //IQueryable<Persoon> FindBepByFullName(string naam, string voorv, string voorl);
        //bool ExistsBep(string naam, string voorv, string voorl, string adres, string huisnr);
        ///<summary>
        ///</summary>
        ///<param name="id"></param>
        ///<returns></returns>
        Persoon SelectUsingPk(int id);
        Persoon SelectUsingPk(int id, string modifier);

        void Add(Persoon persoon);
        
        void Delete(Persoon persoon);

        void Save();
    }
 public class PersoonCollection : IPersoonCollection
    {
        private ContextStartup _contextStartup;
        StamboekCoreEntities db;

        ///<summary>
        ///</summary>
        public PersoonCollection(string modifier)
        {
            _contextStartup = new ContextStartup(modifier);
            db = new StamboekCoreEntities(_contextStartup);
        }


        ///<summary>
        ///</summary>
        ///<param name="lidnr"></param>
        ///<param name="id"></param>
        ///<returns></returns>
        public bool IsLidNrUnique(int lidnr, int id)
        {
            return !db.Persoon.Any(x => x.Lidnr == lidnr && x.Id != id);
        }

        ///<summary>
        ///</summary>
        ///<returns></returns>
        public int NewLidNr()
        {
// ReSharper disable PossibleInvalidOperationException
            var retValue = (int)(db.Persoon.Max(x => x.Lidnr) + 1);
// ReSharper restore PossibleInvalidOperationException
            return retValue;

        }

        ///<summary>
        ///</summary>
        ///<returns></returns>
        public IList<Persoon> RunSelect()
        {
            return RunSelect(string.Empty).ToList();
        }

        ///<summary>
        ///</summary>
        ///<param name="modifier"></param>
        ///<returns></returns>
        public IList<Persoon> RunSelect(string modifier)
        {
            return db.Persoon.OrderBy(d => d.Achternaam).ToList();
        }

        ///<summary>
        ///</summary>
        ///<param name="achternm"></param>
        ///<returns></returns>
        public IList<Persoon> SelectByAchternaam(string achternm)
        {
            return db.Persoon.Where(d => d.Achternaam.Contains(achternm)).ToList();
        }

        ///<summary>
        ///</summary>
        ///<param name="achternm"></param>
        ///<returns></returns>
        public IList<Persoon> SelectAlleLeden()
        {
            return db.Persoon.Where(d => d.Lidnr != null || d.Lidnr > 0).OrderBy(d => d.Lidnr).ToList();
        }
        ///<summary>
        ///</summary>
        ///<param name="achternm"></param>
        ///<returns></returns>
        public IList<Persoon> SelectAlleActieveLeden()
        {
            return db.Persoon.Where(d => (d.Lidnr != null || d.Lidnr > 0) && d.Lid_sinds <= DateTime.Now && (d.Lid_einde >= DateTime.Now || d.Lid_einde == null)).OrderBy(d => d.Lidnr).ToList();
        }
        ///<summary>
        ///</summary>
        ///<param name="achternm"></param>
        ///<returns></returns>
        public Persoon SelectByExactNaam(string achternm, string voorl)
        {
            return db.Persoon.SingleOrDefault(d => d.Achternaam.Equals(achternm) && d.Voorletters.Equals(voorl));
        }

        ///<summary>
        ///</summary>
        ///<param name="startDate"></param>
        ///<param name="endDate"></param>
        ///<param name="modifier"></param>
        ///<returns></returns>
        ///<exception cref="NotImplementedException"></exception>
        public IList<Persoon> SelectByModifiedDateRange(DateTime? startDate, DateTime? endDate, string modifier)
        {
            throw new NotImplementedException();
        }

        ///<summary>
        ///</summary>
        ///<param name="startDate"></param>
        ///<param name="endDate"></param>
        ///<param name="modifier"></param>
        ///<returns></returns>
        ///<exception cref="NotImplementedException"></exception>
        public IList<Persoon> SelectByCreatedDateRange(DateTime? startDate, DateTime? endDate, string modifier)
        {
            throw new NotImplementedException();
        }

        ///<summary>
        ///</summary>
        ///<param name="id"></param>
        ///<returns></returns>
        public Persoon SelectUsingPk(int id)
        {
            return db.Persoon.SingleOrDefault(d => d.Id == id);
        }

        ///<summary>
        ///</summary>
        ///<param name="id"></param>
        ///<param name="modifier"></param>
        ///<returns></returns>
        ///<exception cref="NotImplementedException"></exception>
        public Persoon SelectUsingPk(int id, string modifier)
        {
            throw new NotImplementedException();
        }

        ///<summary>
        ///</summary>
        ///<param name="persoon"></param>
        public void Add(Persoon persoon)
        {
            db.AddItem(persoon);              
        }

        ///<summary>
        ///</summary>
        ///<param name="persoon"></param>
        public void Delete(Persoon persoon)
        {            
            db.DeleteItem(persoon);
        }

        ///<summary>
        ///</summary>
        public void Save()
        {
            db.SaveChanges();
        }
    }
Coordinator
Mar 2, 2011 at 1:30 AM

To your last point: why would you need a generated collection to call the context? This is what you are supposed to do in hand written code. Like RunSelect() is just a wrapper for context.Entity.ToList(). The SelectByPK is the same thing. I see that you are coping this syntax from the ADO.NET DAL but why? I guess I do not see th use of generating this code since it does not wrap any complex logic. What are you trying to use it for?

Mar 2, 2011 at 8:14 PM

nHi,

The posted examples are from the most simple collection I use. I do have more complex data retrieval methods in other collection classes. It true I copied from the NH DAL (is that equal to ADO.NET DAL ?), because I started my project with NHDAL but later on I switched to EFDAL. I did want to do minimum code changes, so I used the same method names.

Why I am using collections ? Because I have learned this way ;) But also I like the principle "seperation of concern". When I do more complex retrieval I dont want that be done in the Controller (with MVC) instead of that I wanna do it in the collection classes.

Why I like to have the collections generated.? Now I have to repeat my self several time to create the collection class, but the basis (see code samples previous posts) of the classes can be created from the generator.

I hope I was able to clarify my self :)