Giter Club home page Giter Club logo

Comments (6)

ericdc1 avatar ericdc1 commented on May 21, 2024 1

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.

scgough avatar scgough commented on May 21, 2024 1

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.

clabnet avatar clabnet commented on May 21, 2024

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.

peter3 avatar peter3 commented on May 21, 2024

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.

kiquenet avatar kiquenet commented on May 21, 2024

Useful method for only update some field values

Usage sample?

Any more alternatives? do you use yet in production?

from dapper.simplecrud.

oghenez avatar oghenez commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.