How do I restrict the number of columns used in an INSERT when using EntityFramework?

dto entity-framework entity-framework-6 entity-framework-core

Question

Let's say you have an Entity with 26 columns. It matches the corresponding table which also has 26 columns.

From time to time I would like to be able to send fewer columns in an INSERT (Add) operation than are specified in the entity because of certain business rules (In our case we have a trigger on a table that will automatically populate certain fields with data. We routinely leave those columns out of our INSERT statements)

I know that I can use DTOs to restrict the number of columns returned, but how do I restrict the number of columns sent?

1
0
1/14/2019 10:55:58 PM

Popular Answer

If there are operations that would insert entities that only provide a subset of columns (non-null-able for example) then you can consider using a bounded context with an entity declaration for just those applicable columns. The bounded context is a smaller, single-purpose context for reading and writing data since a single EF context does not support multiple entity definitions to a single table.

1
1/15/2019 2:34:12 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow