2

i'm thinking about how i would like to structure my query/read layer for my application and i think what i am going to do is create database views to flatten out the model and use entity framework for my data access.

my question is, should i just allow my controllers direct access to my IQueryContext, which is just essentially abstracting the EF context. or should i create a transaction script style query service, like ICustomerQueries that contains all the related reporting methods? or maybe each query is its own concept and lives in its own object ie; GetProductsByCustomerQuery

any help/ideas/arguments would be great!

Marco
  • 2,453
  • 3
  • 25
  • 35
  • Why not skip the database views and flatten the model in EF? – Chris Jul 10 '11 at 00:31
  • because i found myself having to add properties and associations for display purposes only on my domain entities. also, if it sits behind a view, i can change it out to read from a denormalized table if need be. – Marco Jul 10 '11 at 00:41

2 Answers2

2

I'd keep the query side as simple as possible. I'll probably get flamed for this, but in my opinion getting as close to raw SQL as you can, in some cases even down to SELECT * FROM ..., might suffice.

Thus: Expose your flattened out views -- and later your denormalized tables -- via EF or Linq2SQL, and bind them to your UI (I'd even go as far and question the need of an ORM at this point). No further abstraction layers required. Saves time to focus on the Core Domain.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • @iwayneo or a simple key/value store, depending on the requirements. But OP asked about abstracting away the database views, and I tried to answer the specific question. – Dennis Traub Jul 13 '11 at 07:11
1

I tend to use WCF Data Services on the query side. So, I have an Entity Framework model of the Read database, then create a WCF Data Service on top of that (that only takes a few minutes), then query that WCF Data Service.

It's easy, it's consistent, you can configure it for read-only access, it supports LINQ and even the OData protocol, so that you can write queries in your URL.

See also:

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76
  • I am still not convinced about complex reporting + cqrs + es + read model. Do you have any opinions on that Roy? Can wcf data service be used for that? – cs0815 Jun 10 '14 at 12:25
  • What exactly are your requirements, @csetzkom? – Roy Dictus Jun 10 '14 at 14:08
  • It is all based on this: http://stackoverflow.com/questions/24013714/reporting-in-the-cqrs-es-world I guess you do not really know the future reporting needs so will have to create something (?) generic. I guess if you tell management that you will have to create a new dedicated read model and run all/most events past it to full-fill the new reporting needs (instead of writing a sql query) they will tell you to go away ... – cs0815 Jun 10 '14 at 14:25