Print Page | Close Window

Multiple Domain Models

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3589
Printed Date: 14-May-2025 at 10:17pm


Topic: Multiple Domain Models
Posted By: haighis
Subject: Multiple Domain Models
Date Posted: 20-Aug-2012 at 2:35pm
Hello,

I am working with Cocktail 1.0 Silverlight. I have created a test domain model with a unitofwork, factory and repository similar to the StaffingResource unitofwork, etc. inside the TempHire sample and I want to know how the SQL CE database is created? 

Thanks,

John Haigh



Replies:
Posted By: mgood
Date Posted: 20-Aug-2012 at 4:14pm
John,
The SQL CE database is automatically created by Entity Framework. That capability is there if you use Code-First. The DbContext class is responsible for further customizing the creation of the database. Following is the DbContext from TempHire. TempHireDbInitializer is responsible for when and how you want EF to create the database. In this case the database is created every time the model changes or the database doesn't exist and then the Seed method is called to fill it with initial data.
 
   [DataSourceKeyName("TempHireEntities")]
    internal class TempHireDbContext : DbContext
    {
        static TempHireDbContext()
        {
            // This is currently a DevForce requirement in order to use SLQ CE with Code-First.
            // See http://drc.ideablade.com/xwiki/bin/view/Documentation/code-first-sqlce
            // Remove if not using SQL CE.
            Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
        }
 
        public TempHireDbContext(string connection = null)
            : base(connection)
        {
            Database.SetInitializer(new TempHireDbInitializer());
 
            // DevForce already performs validation
            Configuration.ValidateOnSaveEnabled = false;
        }
 
        public DbSet<StaffingResource> StaffingResources { getset; }
        public DbSet<Address> Addresses { getset; }
        public DbSet<AddressType> AddressTypes { getset; }
        public DbSet<PhoneNumber> PhoneNumbers { getset; }
        public DbSet<PhoneNumberType> PhoneNumberTypes { getset; }
        public DbSet<Rate> Rates { getset; }
        public DbSet<RateType> RateTypes { getset; }
        public DbSet<State> States { getset; }
        public DbSet<WorkExperienceItem> WorkExperienceItems { getset; }
        public DbSet<Skill> Skills { getset; }
 
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Ignore<EntityAspect>();
        }
    }


Posted By: mgood
Date Posted: 20-Aug-2012 at 4:17pm
Also, you can read more about this here.
 
http://drc.ideablade.com/xwiki/bin/view/Documentation/advanced-database-connections - http://drc.ideablade.com/xwiki/bin/view/Documentation/advanced-database-connections


Posted By: haighis
Date Posted: 20-Aug-2012 at 5:18pm
Thanks for the information. I ended up reading your links and then I figured it's creating the database when my (or temphire) sample dbcontext is called.  This ended up working btw.



Print Page | Close Window