Can the write database be different to the read database in terms of the data it holds i.e. fields/tables included in one that are not included in the other?
See original GitHub issueThanks again once again for developing this app. I am developing an application using the CQRS pattern. The read database is: MongoDB (NoSQL) and the write database is SQL Server.
Please see the code below:
public class Product
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public void LookupDescriptionByCode(List<ProductDescriptionLookup> productCodes)
{
Description = productCodes.Find(x => x.Code == Code).Description;
}
}
public class ProductDescriptionLookup
{
public Guid Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
}
The database (lookup tables) looks like this:
create table ProductDescriptionLookup(Id uniqueidentifier, Code varchar(100), Description varchar(100)) insert into ProductDescriptionLookup (Id,Code,[Description]) values (newid(), ‘prod1’,‘Product1’)
Here is some test code for the write side:
[Fact]
public void Test()
{
List<ProductDescriptionLookup> list = new List<ProductDescriptionLookup>();
list.Add(new ProductDescriptionLookup { Id = Guid.NewGuid(), Code= "prod1", Description="Product1" });
Product p1 = new Product { Id = Guid.NewGuid(), Code = "prod1", Description = "" };
p1.LookupDescriptionByCode(list);
}
Here is the read model (which is mapped to a MongoDB database):
public class Product
{
public Guid Id { get; set; }
public string Description { get; set; }
}
Notice that the Product Code is not even persisted to the read side. Therefore there is no need for the lookup table on the read side (because it will never have to lookup the description by product code). Therefore I am planning to exclude the ProductDescriptionLookup table from the read side. This works perfectly from a technical point of view, however I am wandering if it is frowned upon from an architectural perepective as the read database is now different to the write database?
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top GitHub Comments
@mvelosop, yes the question was answered - thanks for the answers. I thought a question about the architecture used by eShopContainers would be on topic - apologies if I have gone off topic.
Hey, no problem @w00519772, this is all fun and it’s easy getting carried away 😉
Best.