How to Integration Dapper into Abp Framework - abp

I'm trying to integrate Dapper into the Abp application for reading data only.
Where should I put the repository and be able to access it from the Application layer? The documentation states that I have to pass in my DBContext
Many thanks
Zak

You must put the repository interface in the domain layer and the implementation in the EntityFrameworkCore layer https://docs.abp.io/en/abp/latest/Dapper , in the implementation you inject the dbContext and do the query as shown shows in that example

Related

Managing multiple WCF services in one project

Currently I am working on an ERP Project, Using Entity FrameWork and WCF at server side and WPF at client side. Since it is a big project , we have a lot of entities.What we did so far is, Created Service contracts for each Entities and exposed with multiple endpoints.The Problem is we had to add Service Reference for each Service and we are feeling difficult to manage these web services.
1.Is this a proper way ?
if yes,
2.Is there any way to allocate these web services (in classes or folders)..?
Thanks in advance.
You don't want to keep generating the proxy classes in the client.
Just move the POCO classes and contracts to single assembly which you can reference in the server and client. Then create the necessary channels in the client with ChannelFactory.
ChannelFactory(TChannel)
If you are dealing with many services you can create routing service which will behave like facade. Once you have routing service defined then all requests are going to be sent towards routing service and then, based on some criteria, provided to specific service. You are dealing with only one service so if any change in sub-services occures, for instance endpoint's address is altered, then such a change needs to be reflected only in routing service.
Finally i got how to deal with multiple Services
i am considering to use svcutil.exe in order to create proxy classes.
so that we can arrange those classes in folders, and also we can
get more control over proxies

Best way to connect database for asp.net mvc

I want to know different options available when we are connecting asp.net mvc application to database.
What are pros and cons of each method and what is best method to choose.
In Traditional asp.net web form application i am using DAL approach, which seems to be very useful to me so far even while dealing in shared hosting environment. I want solution which i can apply in shared hosting environment.
Thank you everyone :)
On the website Mikesdotnetting.com, there is an article titled ASP.NET MVC is not all about Linq to SQL. Basically what the article talks about is taking a standard ASP.NET web forms n-layered application and moving it into the world of MVC. The only things that are changed are the actual web forms into views. He leaves much of the application as is, the data access layer, the entity objects, the business rules, etc. From reading the article and seeing what you're asking, I think you can easily use what you know (your DAL) and combine that with MVC.
Good luck on your project, and hope this helps some.
Original Web form based application article:
Building Layered Web Applications with Microsoft ASP.NET 2.0
I use the the following for the data access:
Entity Framework (Code First)
Windsor Container for dependency injection set up with the repository pattern to make my controllers testable without having a database.
Blog post using EF Code First with MVC
Explanation Repository Pattern
Blog post about using MVC3 and Castle Windsor
There are different Ways to Connect to Databases for ASP.NET MVC web application using ENTITY FRAMEWORK :
Code-First
Db-First
Model-First
Code First approach lets you generate databases and datasets automatically .
Use it if you are developing a large Web application and expecting changes of the Models in Future. So you can alter a database after making changes in the Code Accordingly.
Db-First lets you generate models automatically giving good control over Databases. Make sure there is a Database Admin working in the application.
Model-First Approach is not good option as developer would not be having control over both Model and Database.

deploying services to use SQL server in silverlight

I've made a service for my silverlight 4 database (SQL) affairs (VS2010, C# ASP.NET web app), now I'm writing my SQL functions in this service, how can I use this functions? I've read some articles about deploying services but I think my case should not be much complicated, I have a big ASP.net web app with several web pages (I have a server running on winserver2008), it works great, also I have a SL app, what kind of files should I upload for using service? do I need an asmx? how can I create it? should I change anything in web.config?
what is the easiest way to use my service for communicating between SQL and SL? thanks
WCF RIA Services is the way to go. You do not want to bother with old-school ASMX web-services.
You will use an EF model and a DomainContext on the server to handle all database access via CRUD methods (Create, Read, Update & Delete).
On the client you will use the generated Domain Service client to access data.
Notes from my previous RIA post:
My suggestion is to always create RIA Service libraries instead of adding directly to a Silverlight application. Then you can link the Client-side library to any number of Silverlight applications, then link the .Web part of the RIA library to your website to provide the WCF service. Again the key is to migrate the config settings.
It will probably make a lot more sense if you create a new RIA services library project, add your EDM etc, then link the halves to a separate Silverlight app and your new ASP.net website.
Step-by-step:
Create RIA Services Library project by selecting Add New Project. Select Silverlight on the left. Select WCF RIA Services Class Library on the right. I will assume it is called the default name RIAServicesLibrary1 for this example. It will create a Silverlight client library called RIAServicesLibrary1 and a standard .Net library called RIAServicesLibrary1.Web for use by the Web server.
Add your EDMX to the RiaServices.web project. Select Add new item. Select Data on the left. Select ADO.Net Entity Data Model on the right. I will assume it is called the default Model1.edmx for this example. Connect it to your database tables etc.
Build your project so that the next step will find your data model.
Create a Domain Service referencing your EDMX models in your RiaServices.web project. Select Add new item. Select Web on the left. Select Domain Service Class on the right. I will assume it is called DomainService1.cs for this example. Choose your data items from the Add New Domain Service Class popup window by ticking the checkboxes. A set of RIA services objects and methods will be created for each item you select.
Add a reference to the client Ria services library project (RIAServicesLibrary1) to your Silverlight application.
Add a reference to the web RIA services library project (RIAServicesLibrary1.Web) to your hosting web application (e.g. you ASP.Net website).
Copy/merge the various sections in the RIAServicesLibrary1.Web/app.config file into your <webapplication>/web.config file. This will include any connection strings and the module sections.
Build the project again so that the Data Source window will see your new Domain Context data sources.
Use the RIAServicesLibrary1 client object (called DomainService1 in this example) directly from your Silverlight code like this:
DomainService1 client = new DomainService1();
or use the Data Sources window to drag/drop a new grid etc onto a page.
If the Data Sources window is not visible select the "Data" menu then the "Show Data Sources" option.
For more information try this Microsoft link: Using WCF RIA Services

Stuck with MVVM Architecture Problem

I am building a silverlight application using MVVM pattern but I don't understand what I am missing here...
ViewsProject (Silverlight Application) contains user controls and page. References ViewModelsProject.
ViewModelsProject (Silverlight class library) contains backend code of views. Also the business logic will reside in here. It will reference Models project.
ModelsProject (Windows class library) contains: Ado.net entity model of a local database and a WCF RIA DomainService built on the entity model. It's purpose is to get data from the local database and the entities are exposed via domain service.
Web project: Contains xap of ViewsProject.
Have I done everything correct so far? If yes then please help me understand:
How do I call the methods of the
domain service in the ViewsModel
project? If I reference the
ModelsProject, I get the error that
only silverlight projects can be
added.
If I change ModelsProject to a
silverlight class library project
then I can't add the entity model of
my database.
For client projects to use WCF RIA Service you need to set WCF RIA Services Link in project property.
As for modularity and separation in project architecture when using WCF RIA Services,
you can use WCF RIA Class libraries.
There isn't much sense in separating your views from your viewmodels IMHO. I've seen this approach used before but the view model (in my mind at least) represents a more 'view appropriate' abstraction of the data than the domain model can offer. The ViewModel provides a layer of indirection to allow the presentation to change without the model doing the same but it's little more than a sort of Adapter/Controller hybrid and lives alongside the view.
To answer your question though...
Typically, you'll have your SL project call your domain service (a web service usually) via commanding from your view to the viewmodel. The viewmodel command will then directly or indirectly make the web service call. This web service does not need to be a SL class library since it sits on the web server away from your client.
I get the feeling your thinking in terms of a desktop app here. Remember that the SL project runs client side and your data is not there. To wire all this up your gonna need some remote service to get the data from. A regular library reference is no good since the data is not on the client.
HTH, Stimul8d
I worked out the answer.
Change ViewModelsProject (Silverlight class library) to Silverlight Application type.
Check Enable Ria services during creation of the project.
In the view model class, add using ModelsProject.
Compile the ViewModelsProject.
All of the methods of the WCF Ria service will then appear in the code.

Is there any way to reference entity framework in silverlight?

I have a SOA application.
1. data layer: Entity Framework
2. Service layer: WCF
3. presentation layer: silverlight
Now, in silverlight I want to use data types from data layer. I cannot add a direct reference to entity framework because silverlight is using a different .net CLR. So I added a service reference hoping it will recreate thoses types in reference.cs. However, it still doesn't work. The service call return a error message "The remote server returned an error: NotFound.". This only happens when the service function has a entity framework data types as return type. If a function returns a common type like a string, everything will work. So I am almost sure the problem is caused by type translation.
Does anybody know how to reference data types defined in entity framework, in a silverlight project.
Thank you very much!
I believe the current recommended practice when exposing your Entity Data Model to a Silverlight client is to use the new .NET WCF RIA Services. Here is a screencast introduction:
http://www.silverlight.net/learn/videos/all/net-ria-services-intro/
and here is the home page for .NET RIA Services:
http://www.silverlight.net/getstarted/riaservices/
I have been able to simply add a reference to a WCF service that returns entity types. When you do that, Visual Studio will build up similar types in your Silverlight project.
Another option is to use the POCO option in Entity Framework 4. If you create a class library in .NET and then create an identical class library in Silverlight (you can just add the .NET classes using 'add as link'), you should be able to use the same types in your Silverlight app, just make sure to check the "Reuse types in specified referenced assemblies" in the service reference configuration.

Resources