locked
making application workign without SQL Server by data migration ? RRS feed

  • Question

  • User852864959 posted

    I  have to work on an application with  C#, SQL server and EF 4.

    DAL has been implemented using Repository and UoW paterns. Data is being used just for read only purposes. Can you please adivce how Data base can be removed and application can be modified to work by using data from some files, XML or in memory collections.

    Please guide how it can be done usign least changes.

    Thursday, September 6, 2012 9:55 PM

Answers

  • User1779161005 posted

    can you please provide code explaination ?

    Well, that'd be just doing the code for you -- it's simple but not trivial :)

    As for storing the data, I'd think an XML file would work well. That way your update/insert/delete would really just be updating the XML and saving out the entire file each time. It'd not be terribly thread-safe, but it'd work for testing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 6, 2012 11:14 PM

All replies

  • User1779161005 posted

    So if the data is behind a repository then you can just implement a new repository whose implementation is using a file and not a database. Also if everything is read-only then the UoW pattern seems unnecessary.

    Thursday, September 6, 2012 10:06 PM
  • User852864959 posted

    Thanks BrockAllen,

    Actually I am not getting this idea how I should implement this. Here is my generic repository code.

     public  class Repository<T> : IRepository<T> where T : class
        {
    
            protected IObjectSet<T> objectSet;
            protected Entities context;
            
            public Repository(JetStarHRContractGenerationSystemEntities context)
            {
                objectSet = context.CreateObjectSet<T>();
            }
    
            public IEnumerable<T> GetAll()
            {
                return objectSet;
            }
    
            
            public IEnumerable<T> Query(Expression<Func<T, bool>> filter)
            {
                return objectSet.Where(filter);
            }
            public void Add(T entity)
            {
                objectSet.AddObject(entity);
            }
    
            public void Remove(T entity)
            {
                objectSet.DeleteObject(entity);
                
            }   
    
    
            public T GetById(int id)
            {
                throw new NotImplementedException();
            }
        }


    I am confuse how I will put data in cusotm classes ? In form of lists or arrays ? and then how I will attach these classes with my curren code.

    I am jsut considering to let UoW remain implemented so that I may need to do least chagnes.

     Edit: here is code how application is using repository with UoW.

       private Repository<ContractType> contractType;
            public Repository<ContractType> ContractType
            {
                get
                {
    
                    if (this.contractType == null)
                    {
                        this.contractType = new Repository<ContractType>(context);
                    }
                    return contractType;
                }
            }


    Pelase guide me.

    Thursday, September 6, 2012 10:14 PM
  • User1779161005 posted

    Create a class:

    FileRepository : IRepository<YourClass>
    {
        // all the get, save, update & delete methods for class "YourClass"
    }

    You might be able to make a generic FileRepository<T> -- just depends how you want to build it. This ability to replace IRepository<T> for a different concrete class is the point of decoupling (and thus dependency injection and unit testing).

    Thursday, September 6, 2012 10:35 PM
  • User852864959 posted

    @BrockAllen thanks again.

    i got this concept. but there are two things plz.

    1. how to store data, list, array or what ?

    2. then how to use this data inside methods like safe, update, etc  ?

    can you please provide code explaination ?

    Thursday, September 6, 2012 10:52 PM
  • User1779161005 posted

    can you please provide code explaination ?

    Well, that'd be just doing the code for you -- it's simple but not trivial :)

    As for storing the data, I'd think an XML file would work well. That way your update/insert/delete would really just be updating the XML and saving out the entire file each time. It'd not be terribly thread-safe, but it'd work for testing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 6, 2012 11:14 PM