I have created a RIA services class library project and things are not going as I expected. The problem is that when I add domain service classes to the server project, the corresponding domain context classes are not generated on the client project.
I start by creating a new project of type WCF RIA services class library. The generated solution has two projects: RIAServicesLibrary1 (the Silverlight class library project) and RIAServicesLibrary1.Web (the class library that will hold the services).
Then I add a new project item to RIAServicesLibrary1.Web of type DomainServiceClass. I add a sample method so that the resulting class code is:
namespace RIAServicesLibrary1.Web
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.ServiceModel.DomainServices.Hosting;
using System.ServiceModel.DomainServices.Server;
// TODO: Create methods containing your application logic.
[EnableClientAccess()]
public class DomainService1 : DomainService
{
[Invoke]
void DoSomething()
{
}
}
}
Then I generate the whole solution and... nothing happens on the client project. The Generated_Code folder is empty, and the domain context object for the service is not here.
Funny enough, if I add a new item of type Authentication domain service, it works as expected: the file RIAServicesLibrary1.Web.g.cs is created on the client project, containing the AuthenticationDomainService1 class as expected.
So what's happening here? Am I doing something wrong?
Note: I am using Visual Studio 2010 Ultimate RTM and WCF RIA services 1.0.
Change it to:
[Invoke]
public void DoSomething()
{
}
Not having 'public' means there was nothing to generate.
Related
I am following a simple tutorial on connecting databases to a .net core project and I have created a test database and tried to add it into my React js template project. But when I try to add custom db context in program.cs I get an error like this. Here is the code I am using to add db context:
builder.Services.AddDbContext<TransportDBContext>(options =>
options.UseSqlServer("Server=BURAK\\SQLEXPRESS;Database=TransportDB;uid=sa;pwd=123"));
I have searched for similar problems but most of the time it seemed to create problems with customDbContext parameters being non-generic but in my dbContext it looks like this:
public TransportDBContext(DbContextOptions<TransportDBContext> options)
: base(options)
{
}
I am wprking on a project and I have 2 projects in one solution. I added my WCF project and inside it I added an entity framework. Also in Service1.svc I can reach the classes and use them for saving like
public bool saveuser(User user)
{
}
For example User is the name of my database and Its pretty fine working in WCF part but at WPF part Im trying to access this class again to fill this class's object and I using MyClass.ServiceReference1; on the top and Inside one of my method I can not reach this class. What should be the solution why I can not access my class instead I added this WCF service as a service reference and enabled async operations.
Im newbie and thanks
Sincerely
I have a solution with this structure :
ProjectName.Domain ==> contains POCO classes (EntityFramework
code first classes) ProjectName.DataAccess ==> contains DbContext
and EntityFramework mapping codes. ProjectName.Task ==> It's my
bushiness layer . ProjectName.Presnetation.MvcClient ==> It's
ASP.NET MVC web client.
ProjectName.Presentation.SilverlightClient ==> It's Silverlight 5
client. ProjectName.WCFRiaClassLibrary ==> It's layer between
business logic and Silverlight client
I've decided to handle logic such as queries and CRUD operations in business logic and use ProjectName.Task in domain service class.
I can't find any sample that use EF code first approach and load entities from another project , can you please help or give me link ? because when I try to create my DomainService class without wizard I can't find generated proxy classes in silverlight client project .
I'm doing something like this :
[EnableClientAccess()]
public class CrudService : DomainService
{
private readonly IEntityTask _entityTask;
public CrudService(IEntityTask entityTask)
{
_entityTask = entityTask;
}
public IQueryable<Entity> GetAll ()
{
return _entityTask.GetAll().AsQueryable();
}
}
Is this possible to use code first classes from another project with WCF Ria Service ?
What is wrong with my approach?
Defintely possible. Take a look at this question to see possible problems with wcf ria + ef
EDIT:
I've just written a small blog post attaching to it a functional project. You can find it here
Is it possible to use ASP.NET MVC model classes in a Windows Forms application? I referenced the .dll file of my ASP.NET MVC project from my Windows Forms application and I was successfully able to call the models. However, when I tried to build the project, errors suddenly popped up saying the namespace of the ASP.NET MVC project could not be found even though the reference was intact.
Here is one of the issue classes in the Windows Forms Application "BeerRecommenderHelper" that references classes in the ASP.NET MVC 3 project "BeerRecommender":
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using BeerRecommender.Models;
namespace BeerRecommenderHelper.Models
{
public class BeerRecommenderHelperContext : BeerRecommender.Models.BeerRecommenderContext
{
public DbSet<Preference> Preferences { get; set; }
public DbSet<Recommendation> Recommendations { get; set; }
public DbSet<Statistic> Statistics { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
Database.SetInitializer(new BeerRecommenderInitializer());
base.OnModelCreating(modelBuilder);
}
}
}
Yes, if you have your model classes in a separate project, and thes project doesn't contain any references that are specific for an MVC or web project you're free to use the models in your winform project. If both projects use the same 'backend' logic than i would suggest this a good approach!
What are the errors you get when building the project?
I have the following Ria Service define:
namespace SilverlightTest.Web
{
[EnableClientAccess()]
public class ContactService : LinqToEntitiesDomainService<AdventureWorksEntities>
{
public IQueryable<Contact> GetContactSearch(string lastName)
{
ContactRepository rep = new ContactRepository();
return rep.SearchByLastName(lastName);
}
}
}
When I compile the solution, my SilverlightTest project does create the SilverlightTest.Web.g.cs file and the appropriate Context objects are created when I look at it. However, when I attempt to import the SilverlightTest.Web namespace to access the Data Context class for the above service, it says it cannot find the Web namespace.
The only difference I can see between what I'm doing and many examples that are out there on the web is that my AdventureWorksEntities data context is located in a separate business object dll. I tried to query the context directly instead of using the Repository Pattern I'm attempting to do and it also isn't work working.
Any ideas? Is it possible to have Ria Services access a separate DLL handling data access or does it HAVE to be in the same project?
I've been able to put the Ria service in a separate project before, although I do remember having issues. Not sure exactly what it was, but I would check two things: your references and your web.config (in the hosting website). When you add a ria service to a web project it does some things behind the scenes that wire everything up correctly.
Could try adding a service to your web project temporarily and see what it adds.
It seems that Resharper does not recognize the .gs files and their name spaces. If you disable R# or just code without intelisense it works.