New Posts New Posts RSS Feed: Multiple Domain Models
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Multiple Domain Models

 Post Reply Post Reply
Author
haighis View Drop Down
Newbie
Newbie


Joined: 20-Aug-2012
Posts: 2
Post Options Post Options   Quote haighis Quote  Post ReplyReply Direct Link To This Post Topic: Multiple Domain Models
    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
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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>();
        }
    }
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 20-Aug-2012 at 4:17pm
Back to Top
haighis View Drop Down
Newbie
Newbie


Joined: 20-Aug-2012
Posts: 2
Post Options Post Options   Quote haighis Quote  Post ReplyReply Direct Link To This Post 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.

Edited by haighis - 20-Aug-2012 at 5:34pm
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down