简体   繁体   中英

What's the proper way to set up a WCF service with a EF database?

I'm working on a project to become more familiar with WCF services and Entity Framework and I ran into a road block. I currently have a simple WCF service with an EF code first database context implemented in a separate class library. I also have a console application to host the service and a client to use the service. This leaves me with the following 2 questions:

  1. Given that I'm using 'code first to a new database', where is the proper place to initialize the database? Would the service itself handle this or should it be initialized within the service host? My idea was to create/initialize the database within the host and treat it as an existing database within the service.

  2. A regular user client should only have read access to the database; however, I'll need something along the lines of an 'admin' client that has the ability to add/remove entries. What is the correct way to have multiple clients access the database through a single service, but provide them with different permissions?

I've taken a look at the following two articles - this one and this one . However, these both discuss using an existing database and didn't really answer my questions. Thanks in advance!

1) The service host should not know about your DB platform as in the next day you can host your as service as windows service for example and don't want do copy code between hosts,so it's better to initalize in the service (by using a separated DAL)

2) Mange your application privileges and pass those access token from each client, You can base your code to sync with AD,Self-development ot any other method you will like

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM