Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using System.Xml.Serialization;
  4.  
  5. namespace CFDE.Model
  6. {
  7. [XmlRoot(ElementName = "OwnershipPeriod")]
  8. public class OwnershipPeriod : ChathamBase
  9. {
  10. [XmlElement(ElementName = "OwnershipPercentage")]
  11. [Column(TypeName = "decimal")]
  12. public Nullable<decimal> OwnershipPercentage;
  13.  
  14.  
  15. [XmlElement(ElementName = "OwnershipPercentageEffectiveDate")]
  16. [Column(TypeName = "datetime")]
  17. public Nullable<DateTime> OwnershipPercentageEffectiveDate;
  18.  
  19. [XmlElement(ElementName = "OwnershipStructure")]
  20. [Column(TypeName = "varchar")]
  21. public string OwnershipStructure;
  22. }
  23. }
  24.  
  25. using System;
  26. using System.Collections.Generic;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Threading.Tasks;
  30.  
  31. namespace CFDE.Model
  32. {
  33. interface IChathamBase
  34. {
  35. int TransactionIdentifier { get; set; }
  36. }
  37.  
  38.  
  39. public class ChathamBase : IChathamBase
  40. {
  41. public int TransactionIdentifier { get; set; }
  42. }
  43. }
  44.  
  45. internal static void BulkUpsert(string connectionName, List<OwnershipPeriod> op)
  46. {
  47. BulkOperations bulk = new BulkOperations();
  48.  
  49. using (TransactionScope trans = new TransactionScope())
  50. {
  51. using (SqlConnection cn = GetConnection(connectionName))
  52. {
  53. bulk.Setup<OwnershipPeriod>()
  54. .ForCollection(op)
  55. .WithTable("OwnershipPeriod")
  56. .AddAllColumns()
  57. //.AddColumn(x => x.TransactionIdentifier)
  58. //.AddColumn(x => x.OwnershipPercentage)
  59. .BulkInsertOrUpdate()
  60. //.SetIdentityColumn(x => x.TransactionIdentifier)
  61. .MatchTargetOn(x => x.TransactionIdentifier)
  62. .Commit(cn);
  63. }
  64.  
  65. trans.Complete();
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement