New Posts New Posts RSS Feed: DevForce 2012, Silverlight template, EF Code First - custom DbContext doesn't work
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DevForce 2012, Silverlight template, EF Code First - custom DbContext doesn't work

 Post Reply Post Reply
Author
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 Topic: DevForce 2012, Silverlight template, EF Code First - custom DbContext doesn't work
    Posted: 09-Jan-2013 at 5:19pm
I must have been unclear. Cocktail does not have any server functionality. Just like Caliburn.Micro, Cocktail is a client-only framework. It interfaces with DevForce on the client. Nowhere in the documentation is there talk of any server functionality. The Hello World examples under Getting started walk you through the basic steps of getting going with Cocktail.
Back to Top
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jan-2013 at 1:44pm
Thanks for clarification.

Never install Cocktail to the server project?
The description of the Cocktail package: 'Cocktail is a blend of three popular frameworks: Caliburn.Micro + DevForce + EntityFramework'.
You must admit, that it can be misleading.

I know, I know ...
- install Cocktail on server and client if DevForce is not installed
- install Cocktail on client only if DevForce is installed.

So ... why don't you devide Cocktail and name each part: 'Cocktail 2012 Server' and 'Cocktail 2012 Client' in the same way as 'DevForce 2012 Server', 'DevForce 2012 Client'? You as a producer should be consistent, don't you? :)

BTW, I'm impressed of IdeaBlade suport (I feel safe).

Thanks.
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: 09-Jan-2013 at 3:29am
Originally posted by zbig

After applying your code for querying, it works OK.

Thanks a lot!

Web project is always set as startup project (probably something has been changed during opening unpacked solution in VS).

As for Nuget - after starting Silverlight Template project, I have installed Cocktail and this automatically installed AsyncPanck (didn't know that this is not necessary). When Cocktail was installed, both projects client and web are checked - it suggests, that should be checked (unnecessary packages already uninstalled, but would be nice if installer would install only necessary items).

Zbig


Zbig,
The DevForce NuGet package installs the Microsoft Async Pack, which is required. Kim was talking about the Cocktail Async Pack for VS 2012. That's different. 

If you install NuGet packages at the solution level it will always check all projects. Unfortunately, there's nothing in NuGet to limit applicability of packages to only certain projects. You as a developer have to know which package should be installed to which project and as Kim said, never install Cocktail to the web server project. You actually need to install the DevForce Server package to the web server project. 
Back to Top
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jan-2013 at 12:35pm
After applying your code for querying, it works OK.

Thanks a lot!

Web project is always set as startup project (probably something has been changed during opening unpacked solution in VS).

As for Nuget - after starting Silverlight Template project, I have installed Cocktail and this automatically installed AsyncPanck (didn't know that this is not necessary). When Cocktail was installed, both projects client and web are checked - it suggests, that should be checked (unnecessary packages already uninstalled, but would be nice if installer would install only necessary items).

Zbig

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jan-2013 at 3:05pm
A few things going on here -
 
First, when testing a Silverlight solution within Visual Studio always make sure that the web project is the startup project.  This allows the Silverlight application to make calls to the EntityService in the web application project.
 
Next, as a Silverlight application, you can't make synchronous calls for data unless you only want to query the memory cache.  So for example, here you'd await the async query like this:

  var  aaa = await manager.GetQuery<TestEntity>().AsScalarAsync().FirstOrDefault();
 
Also be careful with some of your NuGet references.  The Cocktail AsyncPack for VS2012 (Silverlight) is intended for DevForce 2010 applications.  Cocktail 2012 is a client-side framework, so you won't generally require it in your web application.
 
If you plan to use Cocktail, the TempHire reference application is an excellent resource:  http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-reference-application.
Back to Top
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jan-2013 at 2:08pm
Yes, RrDbContext is included and its Build Action is assigned as 'Compile'.

Please find attached the solution. I've removed bin/obj folders, Rr.xap and content of packages folders to make the zip file size acceptable by this site.

Please find attached screenshots with installed packages, too (all from DevForce).

Zbig

DefForce_Rr_Test.zip





Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jan-2013 at 11:55am
This is a very simple solution, and I can't think why your custom DbContext class is not being found.  The file holding the RrDbContext class is included in the server project with a build action of "Compile" I'd guess.  Can you zip up the solution and upload here or send to us (IdeaBladeSupport) so we can take a quick look? 
 
 
Back to Top
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jan-2013 at 11:40am
DevForce 2012 Code First is installed, both client and server side.
PostSharp is installed, both client and server side.
Deleting .ibmmx file and rebuilding server project gives no error - .ibmmx is recreated.
Rebuilding the solution gives no error.


web.config:

<?xml version="1.0"?>
<configuration>
<configSections>
    <section name="ideablade.configuration"
             type="IdeaBlade.Core.Configuration.IdeaBladeSection, IdeaBlade.Core"/>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework"
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
             requirePermission="false"/>
</configSections>
<connectionStrings>
    <!-- Remember to add your connection string(s) here -->
    <add name="RrDbContext"
        connectionString="Data Source=(LocalDb)\Projects;Initial Catalog=RrDbContext;Integrated Security=True" />
</connectionStrings>
<ideablade.configuration version="6.00"
                           xmlns="http://schemas.ideablade.com/2010/IdeaBladeConfig">
    <!-- See the DevForce Resource Center for more information on configuration settings:
   http://drc.ideablade.com/devforce-2012/bin/view/Documentation/deploy-iis#HConfiguration
    -->
</ideablade.configuration>
<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
</entityFramework>
<system.web>
    <compilation debug="true"/>
</system.web>
</configuration>



Entity:

    [ProvideEntityAspect]
    public class TestEntity
    {
        public int TestEntityId { get; set; }

        [Required]
        [StringLength(15)]
        public string Name { get; set; }
    }


Custom EntityManager:

    [DataSourceKeyName("RrDbContext")]
    public class TestEntities : EntityManager
    {
        public EntityQuery<TestEntity> TestEntitiesQuery { get; set; }

        public TestEntities(bool shouldConnect)
            : base(shouldConnect)
        {
       
        }

    }



Custom DbContext:


[DataSourceKeyName("RrDbContext")]
    public class RrDbContext : DbContext
    {
        public RrDbContext(string connection = null)
            : base(connection)
        {
            Database.SetInitializer(new DropCreateDatabaseAlways<RrDbContext>());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Ignore<EntityAspect>();

        }

        public DbSet<TestEntity> TestEntitySet { get; set; }

    }


This is very simple, test solution.
When the client executes query, constructor of the custom EntityManager (TestEntities) is executed, but the custom DbContext (RrDbContext) constructor - not and DB is not created.

Zbig




Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 05-Jan-2013 at 3:52pm
Did you install the DevForce 2012 Code First NuGet package to both projects?  This will also install PostSharp support.
 
Try deleting the .ibmmx file and rebuilding.  If this fails the error message should indicate what might be wrong.  If the .ibmmx is regenerated and the error only occurs at runtime, please let us know what error you're seeing. 
Back to Top
zbig View Drop Down
Newbie
Newbie
Avatar

Joined: 13-Oct-2012
Posts: 28
Post Options Post Options   Quote zbig Quote  Post ReplyReply Direct Link To This Post Posted: 05-Jan-2013 at 2:44pm
Hi All,

I'm starting Silverlight app:
- Windows 8, VS 2012, LocalDb
- Silverlight template
- DevForce 2012 v. 7.0.3.0 (Universal)
- EF Code First (5.0) - installed automatically with DevForce
- DevForce.cf file exists (server side)
- .ibmmx file exists (server side and link on client side)
- only one simple entity in model with two properties (EntityId, Name)
- entity has [ProvideEntityAspect] attribute
- custom EntityManager with [DataSourceKeyName("NameOfDbContext")] attr. exists
- custom DbContext with [DataSourceKeyName("NameOfDbContext")] attr. exists (same as in EntityManager)
- connection string with 'name' attr.: "NameOfDbContext" (same as above) exists
- Entity and EntityManager linked to the client Shared_Code folder

... everything done as described in docummentation.

When the client side query is executed for the first time, custom DbContext doesn't work. It means that constructor of the custom DbContext is not executed and database is not created (constructor contains Database.SetInitializer ... CreateDatabaseAlways).

What might be wrong?

Thanks in advance.

Zbig
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down