logo
down
shadow

Dapper control dates


Dapper control dates

By : Kallela
Date : November 28 2020, 11:01 PM
wish help you to fix your issue I've ran into a case where I was working with a database that was consumed by both Rails and Dapper. Rails was managing created_at and updated_at, not the database. So with the .net application I had to implement a solution that managed these and provided the ability to add additional business logic at these layers such as events.
I've included a basic example of how I handled this with a wrapper around Dapper Simple Crud for inserts and updates. This example does not include exposing the other critical methods from dapper and simplecrud such as Query, GET, Delete, etc. You will need to expose those at your discresion.
code :
[Table("examples")]
public partial class example
{
    [Key]
    public virtual int id { get; set; }
    [Required(AllowEmptyStrings = false)]
    [StringLength(36)]
    public virtual string name { get; set; }
    [Dapper.IgnoreUpdate]
    public virtual DateTime created_at { get; set; }
    public virtual DateTime updated_at { get; set; }
}

public class ExampleRepository : IExampleRepository
{
    private readonly IYourDapperWrapper db;

    public PartnerRepository(IYourDapperWrapper yourDapperWrapper){
        if (yourDapperWrapper == null) throw new ArgumentNullException(nameof(yourDapperWrapper));
        db = yourDapperWrapper;
    }

    public void Update(example exampleObj)
    {
      db.Update(exampleObj);
    }

    public example Create(example exampleObj)
    {
      var result = db.Insert(exampleObj);
      if (result.HasValue) exampleObj.id = result.value;
      return exampleObj;
    }
}

public class YourDapperWrapper : IYourDapperWrapper
{
    private IDbConnectionFactory db;

    public YourDapperWrapper(IDbConnectionFactory dbConnectionFactory){
      if (dbConnectionFactory == null) throw new ArgumentNullException(nameof(dbConnectionFactory));
      db = dbConnectionFactory;
    }

    public int Insert(object model, IDbTransaction transaction = null, int? commandTimeout = null)
    {
      DateUpdate(model, true);
      var results = Db.NewConnection().Insert(model, transaction, commandTimeout);
      if (!results.HasValue || results == 0) throw new DataException("Failed to insert object.");
      return results;
    }

    public int Update(object model, IDbTransaction transaction = null, int? commandTimeout = null)
    {
      DateUpdate(model, false);
      var results = Db.NewConnection().Update(model, transaction, commandTimeout);
      if (!results.HasValue || results == 0) throw new DataException("Failed to update object.");     
      return results;
    }

    private void DateUpdate(object model, bool isInsert)
    {
      model.GetType().GetProperty("updated_at")?.SetValue(model, DateTime.UtcNow, null);
      if (isInsert) model.GetType().GetProperty("created_at")?.SetValue(model, DateTime.UtcNow, null);
    }
}


Share : facebook icon twitter icon
How to do an insert and update for an object with a navigation property using Dapper.Rainbow (or optionally using Dapper

How to do an insert and update for an object with a navigation property using Dapper.Rainbow (or optionally using Dapper


By : Dmitriy G
Date : March 29 2020, 07:55 AM
will help you Not With Dapper.Rainbow
This is not possible with Dapper.Rainbow in its current form but my pull request in github make this possible.
code :
public class Product {
    public int Id {get;set;}

    public string Name {get;set;}

    [Write(false)] // tell Dapper to exclude this field from the sql
    public ProductCategory Category {get;set;}

    public int CategoryId {get;set;}
}
public interface IProduct {
    int Id {get;set;}
    string Name {get;set;}
    ProductCategory Category {get;set;}
    int Category {get;set;}
}

// and implement it on my Product class
public class Product : IProduct {
    public int Id {get;set;}

    public string Name {get;set;}

    [Write(false)]
    public ProductCategory Category {get;set;}

    int Category {get;set;}
}
var product = connection.Get<IProduct>(id);
public interface IProduct {
    // I will not discuss here what this attribute does
    // as this is documented already in the github source.
    // Just take note that this is needed,
    // both here and in the implementing class.
    [Key]
    int Id {get;set;}

    string Name {get;set;}

    [Write(false)]
    ProductCategory Category {get;set;}

    int Category {get;set;}
}

// and implement it on my Product class
public class Product : IProduct {
    [Key]        
    public int Id {get;set;}

    public string Name {get;set;}

    [Write(false)]
    public ProductCategory Category {get;set;}

    int Category {get;set;}
}
Dapper complex mapping Dapper.Extensions Dapper.FluentMap

Dapper complex mapping Dapper.Extensions Dapper.FluentMap


By : user3052407
Date : March 29 2020, 07:55 AM
wish helps you I have a bit of a problem with my code and getting dapper to play nicely with it. , Have you tried sth like that:
code :
Feed feed = null;

var sql =
@"
SELECT * FROM Feeds WHERE FeedId= @FeedId
SELECT InboundProperties_ExternalRef as ExternalRef, InboundProperties_ExternalRefPrevious as ExternalRefPrevious FROM Feeds as InboundProperties WHERE FeedId= @FeedId
SELECT * FROM FeedFilterParameters WHERE FeedId = @FeedId
SELECT * FROM TeamFeeds WHERE FeedId = @FeedId";

using (var multi = DbConnection.QueryMultiple(sql, new { FeedId = feedId }))
{
    feed = multi.Read<Feed>().Single();
    feed.InboundProperties = multi.Read<InboundProperties>().Single();
    feed.Parameters = multi.Read<FeedFilterParameter>().ToList();
    feed.TeamFeeds = multi.Read<TeamFeed>().ToList();
} 

return feed;
Dapper is converting my dates into 01-Jan-01 and I cannot see why?

Dapper is converting my dates into 01-Jan-01 and I cannot see why?


By : user2210677
Date : March 29 2020, 07:55 AM
may help you . @John has it correct in his comment. The name of the property (here CreationDateTime) generally must match the name of the column (here CreationTime). Having that said, it is not really the name of the table column, but the name of the result column, so you could do something like this:
code :
SELECT CreationTime as CreationDateTime, ...
How to select dates after three dates from current date using ajax control kit

How to select dates after three dates from current date using ajax control kit


By : HeroicNonsense
Date : March 29 2020, 07:55 AM
this will help How can i disable all future dates after three days from current date (Today) in AJAX control kit , To select date which is greater than 3 days:
code :
var date = new Date();
date.setDate(date.getDate() + 3);
if(selected_date > date){
   // code here
}

<script type="text/javascript">
  function checkProjectEndDate(sender, args) {

    var future_date = new Date();
    future_date.setDate(future_date.getDate() + 2);

    if (sender._selectedDate > future_date) {
      alert("You can not select a future date than today!");
      sender._selectedDate = new Date();
      sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }
  }
</script>
Formatting the dates to desired format return invalid dates in python. How to control it?

Formatting the dates to desired format return invalid dates in python. How to control it?


By : Mike Rief
Date : March 29 2020, 07:55 AM
Hope this helps You can't, at least not with 100 % reliability. If your date formats are this hopelessly mixed, you will never be able to tell if 04/06/2013 is supposed to be April 6th or June 4th.
Your only chance is to take the more common variant and try that first. If that throws an error or returns an implausible date (like one in the future, if those are not permitted), try the next one.
Related Posts Related Posts :
  • Connect SendObserver to ISendEndpoint obtained by consume context once
  • Constructing Hetereogenous Type Lists in Rust
  • Batch rename with command line
  • How do I get the elastic load balancer dns name?
  • How to get the path where the library is installed
  • ZF2 ACL check link in view
  • iTunes Connect Screenshot 5"5 format
  • Retrieving data feed from a closed Facebook group
  • Spring (Boot) application and csrf
  • Argon.js: Error: A frame state has not yet been received
  • Uncaught exception: -[AccessibilitySettingsController setAXInspectorEnabled:specifier:]: unrecognized selector sent to i
  • Nancy register dependency with type argument
  • How to set string date in store to date textbox inside a dojo grid
  • clEnqueueNDRangeKernel' failed with error 'out of resources'
  • JavaFX : TableView inside Dialog has duplicate items
  • How to make synchronous url requests with swift 3
  • how to access source code of PolSARpro
  • ABAC with keycloak - Using Resource attributes in policy
  • backpack-for-laravel Error install backpack for Laravel 5.3
  • How can i add custom fields in moodle assignment plugin?
  • Show executed query in Microsoft SQL Server 2016
  • How to integrate Grunt with project from eclipse.
  • How to sort items from shortest to longest
  • The module "APT50.dll" failed to load
  • Kentico ASCX transformation page type properties
  • The expression you entered contains invalid syntax
  • Android N showing warning alert in Zbar .SO File
  • CPU usage too high while running Ruta Script
  • UITableView load ONCE all cells in background
  • pygame: how to display full-screen without cutting off edges
  • Changing Kademlia Metric - Unidirectional Property Importance
  • Yii2 redirect 404 Page not found
  • How can I emit more values after emit an error?
  • How can I integrate my Bot (created with the Bot Framework) with Spark?
  • Install4j silent updater process hangs in case of incorrect proxy settings
  • How to force view controller orientation in iOS 10?
  • sbt dependsOn, typesafe config merges application.conf
  • Global optimization of polynomial in several variables in Maple?
  • Is there a way to monitor a SQL Server service with ZABBIX?
  • Can't install cygnus-ngsi via Docker
  • API time zone representation
  • Animation of SVG doesnt work
  • How to define and invoke inline a lambda expression in Java
  • Wit.ai - When are the actions triggered?
  • TIBCO SPOTFIRE Time on y-axis (avg duration)
  • Google PubSub Emulator: How to configure logging level
  • Run script in relative path via System.cmd in elixir
  • WSO2 Identity Server: SLO redirect not working as expected
  • Windows Mobil Apps Store Define Install and Uninstall
  • Not able to detect Kurento Media Server crash
  • Flow control in pushtechnology diffusion server delaying publishing client updates
  • Geolocalization user search: Twitter API
  • Changing the filter header in Kibana?
  • Valgrind suppression and return code
  • How can I get female voice by Web Speech API in Google Chrome
  • Strategy for quick icon generation for labview?
  • STM32 internal clocks
  • OrientDB callback after record is persisted in server
  • Position of scaling points
  • Limit nested objects results in rethinkdb query
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com