locked
Error creating RIA Service "...cannot be used as a type parameter..." RRS feed

  • Question

  • I am trying to add a RIA service to my LightSwitch app and am getting an error.  (I am eventually trying to get this to work with stored procedures and UDFs, but right now, I am just trying to get it to work with one table.)

    1) I added a class library project called "WCF_RIA".

    2) I added an ADO.NET Entity Data Model, selected one table for testing and created the edmx.

    3) I added a class file for my domain service called "TPE_Domain_Service"'

    I added the following code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Server;
    
    namespace WCF_RIA
    {
       public class TPE_DomainService : LinqToEntitiesDomainService<tpe1Entities>
       {
       }
    }

    I am getting this error:

    Error 2 The type 'WCF_RIA.tpe1Entities' cannot be used as type parameter 'TContext' in the generic type or method 'System.ServiceModel.DomainServices.EntityFramework.LinqToEntitiesDomainService<TContext>'. There is no implicit reference conversion from 'WCF_RIA.tpe1Entities' to 'System.Data.Objects.ObjectContext'. C:\Users\Mark\Documents\Visual Studio 2013\Projects\PE1\WCF_RIA\TPE_DomainService.cs 13 17 WCF_RIA

    Here is the auto-generated code in tpe1.Context.cs:

    namespace WCF_RIA
    {
        using System;
        using System.Data.Entity;
        using System.Data.Entity.Infrastructure;
        
        public partial class tpe1Entities : DbContext
        {
            public tpe1Entities()
                : base("name=tpe1Entities")
            {
            }
        
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                throw new UnintentionalCodeFirstException();
            }
        
            public DbSet<Clients> Clients { get; set; }
        }
    }

    I don't know what this error means. Any help would be greatly appreciated.

    Thanks,

    Mark



    • Edited by marks100 Monday, July 21, 2014 8:07 PM
    Monday, July 21, 2014 8:06 PM

Answers

  • Mark,

    Your Domain Service is expecting an ObjectContext but your Entities have been generated with DbContext.

    You might try to regenerate the Entities using the ObjectContext templates. I have not used LightSwitch but, in VS if you open the Model (.edmx ). Right click on the design surface and add a new code item, choose Entity Framework Object Context.  You might need to remove the DbContext entities file to avoid namespace conflicts.

    Brad


    • Marked as answer by Angie Xu Monday, August 3, 2015 6:06 AM
    Wednesday, July 22, 2015 5:52 PM

All replies