Comments (6)
I suggest using either of these in your POCO model on the properties you want to exclude.
[Editable(false)]
[ReadOnly(true)]
Documentation on this below:
By default the insert statement would include all properties in the class - The Editable(false) and ReadOnly(true) attributes remove items from the insert statement
Properties decorated with ReadOnly(true) are only used for selects
Complex types are not included in the insert statement - This keeps the List out of the insert even without the Editable attribute. You can include complex types if you decorate them with Editable(true). This is useful for enumerators.
from dapper.simplecrud.
Hi @peter3 - great method. 👍 It's been very handy. I've got a small bug with it though.
In SQL Server, if the table name being updated is named using a reserved word (e.g. User
) then the method doesn't nicely wrap up the name (like the main insert/update methods do) and gives me an error.
In this example, it should write the SQL as UPDATE [User] set ...
but it is writing UPDATE User set...
EDIT: I've tested and the following line should be changed to:
var sql = string.Format("UPDATE {1} SET {0} WHERE Id=@Id", string.Join(",", names.Select(t => { t = t + "=@" + t; return t; })), GetTableName(typeof(T)));
from dapper.simplecrud.
I don't tried it, for my opinion the idea is very useful.
It is a function already present in OrmLite, for example.
from dapper.simplecrud.
Using the attributes is only useful if you always want to exclude the same fields. If you have a more dynamic environment where the fields to exclude/include can vary, this helper handles that (for example, you have a file upload table and you want to be able to change the filename without also having to fetch and re-post the possibly large file data, but you also want to be able to upload new data in a separate action).
from dapper.simplecrud.
Useful method for only update some field values
Usage sample?
Any more alternatives? do you use yet in production?
from dapper.simplecrud.
I don't tried it, for my opinion the idea is very useful. It is a function already present in OrmLite, for example.
i would have used Ormlite, but it isnt free. and is it also supports only .net 4.5 upwards. the project i am working on is currently .net 4.0 only
from dapper.simplecrud.
Related Issues (20)
- SimpleCrud works using oracle driver but not odbc
- Insert with Guid as Key: Inconsistent behaviour async/sync
- When inserting entity with int? Id assigned a value other than null, the assigned value is returned instead of the inserted entity's Id HOT 1
- Add fluent config in separate class
- Type Handler not being called for SimpleCRUD extensions HOT 2
- Support mordern sqlserver page query like OFFSET ROWS FETCH NEXT
- Does the library only support SQL Server and not Oracle?
- Attribute for selective inclusion of columns in insert/update HOT 1
- How to insert in CLOB columns with SimpleCRUD ?
- _getIdentitySql for postgres misaligns with actual id of inserted entity
- Tons of exceptions thrown in trying to generate CRUD, PostgreSQL DB
- Using Guids without Guid type in the database (MariaDB)
- GetListPagedAsync fails on table with HierarchyID field type
- System.IndexOutOfRangeException Index was outside the bounds of the array.
- Complex fields not included in SELECT/UPDATE queries
- Question: A primary key that is not identity. HOT 1
- Add support for DateOnly and TimeOnly
- Ignore Update if property value is null
- Support for composite keys ? HOT 1
- it is a bug about string whereCondition HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dapper.simplecrud.