Category Archives: c#

PostgreSQL – new jsonb feature exploration – insert, query, index

In this post, I will explore the (not really new) postgreSQL jsonb feature as my objective is to compare nosql performance in real scenarii.

Prerequisite:
  • postgreSQL 9.4.4 installed (you can check by issuing the following : select version();)
  • pgAdmin installed
  • this runs on a HP probook 6560b
    • Processor Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz, 2501 Mhz, 2 Core(s), 4 Logical Processor(s)
    • 16 G of ram
Roadmap

Generate Poco classes from SqlServer or Oracle using CExtensions.EFModelGenerator

This post is about a new library CExtensions-EFModelGenerator for generating poco and dbcontext classes from Oracle or Sqlserver databases.
(support for other databases can be provided through customization).

with this library it could also be possible to generate code for java, javascript and other by implementing a custom Serializer (check the Test for mor info and more samples).

This post guides you through how to generate code from Sqlserver. (also check the Sample folder in the repo)
Continue reading Generate Poco classes from SqlServer or Oracle using CExtensions.EFModelGenerator

Facebook Flux Pattern implementation in .Net (c#): Startup

(Code on Github : Flux.Net)

These days, I took some time to learn facebook’s React and like everyone, came across their Flux Pattern. if I can resume or take one sentence that seemed to be important is this idea:

Flux is used to have a more predictable system.

When looking at the pattern, and trying their Todo or Chat apps, it is not really clear where the call to the server occurs or at least it’s not yet standardized.(as far as I know).

Flux is stated to be a frontend framework, but wait, why would this pattern be more obvious as a frontend pattern.
Continue reading Facebook Flux Pattern implementation in .Net (c#): Startup

Entity Framework – comparing the content of two DbContext (EF 6.1)

Did you ever want to compare the content of two DbContext and getting a list of all differences between both.

for example, you have one context containing :

  <Root>
    <AUTHOR>
      <AUT_ID>1</AUT_ID>
      <AUT_FIRSTNAME>Cedric</AUT_FIRSTNAME>
      <AUT_LASTNAME>Dumont</AUT_LASTNAME>
    </AUTHOR>
  </Root>

and another containing :

  <Root>
    <AUTHOR>
      <AUT_ID>1</AUT_ID>
      <AUT_FIRSTNAME>Cedric123</AUT_FIRSTNAME>
    </AUTHOR>
  </Root>

you would like to have a message telling you this:

Found at least 2 Differences :
1 / Author.FirstName Should be [Cedric] but was [Cedric123] – object with AUT_ID : 1
2 / Author.LastName Should be [Dumont] but was [(null)] – object with AUT_ID : 1

then you would probably check this

PM> Install-Package CExtensions.EntityFramework -Pre

and code this


var comparisonResult = await appContext.CompareTo(expectedContext);

var errorMessage = comparisonResult.ToString();

check whole project on github – CExtensions-Net

Entity Framework – Get the mapping between Table, Entity, Properties and Columns at runtime (EF 6.1)

Recently, I wanted to dump the content of a DbContext. Therefor, I needed to know some information on how Entity and properties were mapping to Tables and columns. (I wanted the output to contain table and column names from my DB schema)
If you are in the same situation, just check the following project : CExtensions-Net.

Get the package from nuget :(from version 1.1.0 in pre at the time of writing)

  Install-Package CExtensions.EntityFramework -Pre

With this in place, getting the mapping for an entity is as simple as:


  var entityMapping = someDbContext.GetMappings<Author>();
 
  entityMapping.Table.ShouldBe("AUTHOR");
  entityMapping.MappedColumn("FirstName").ShouldBe("AUT_FIRSTNAME");

If you want to know the mapping for some Table, just do this:


  entityMapping = someDbContext.GetMappings("AUTHOR");
  
  entityMapping.Entity.ShouldBe("Author");
  entityMapping.ClrType.ShouldBe(typeof(Author));
                

Entity Framework – export your context as xml

Ever wanted to export your context as XML and get a representation of what is contained in it’s local view or with all linked properties even if not already loaded in your context.

  • create an entity
  • add it to the context
  • get it’s xml representation.
Author cedric = new Author() { 
                    FirstName = "Cedric", 
                    LastName = "Dumont" 
                  };
simpleContext.Authors.Add(cedric);

string s = await appContext.AsXmlAsync();

  • will result in :
<Root>
  <AUTHOR>
    <AUT_ID>1</AUT_ID>
    <AUT_FIRSTNAME>Cedric</AUT_FIRSTNAME>
    <AUT_LASTNAME>Dumont</AUT_LASTNAME>
  </AUTHOR>
</Root>
  • to do this, you will need this

PM> Install-Package CExtensions.EntityFramework -Pre

EntityFramework in memory testing with xml files

Lately I wanted to test entity framework using input xml files and expected xml files. So I started an open source project CExtensions.Effort as I could find something that fitted my needs.

so if you would like to have this as your DbContext input :

  
            <Root>
              <AUTHOR>
                <AUT_ID>1</AUT_ID>
                <AUT_FIRSTNAME>John</AUT_FIRSTNAME>
                <AUT_LASTNAME>DOEDOE</AUT_LASTNAME>
                <AUT_EXPERIENCE>12</AUT_EXPERIENCE>
              </AUTHOR>
              <AUTHOR>
                <AUT_ID>2</AUT_ID>
                <AUT_FIRSTNAME>Albert</AUT_FIRSTNAME>
                <AUT_LASTNAME>Einstein</AUT_LASTNAME>
                <AUT_EXPERIENCE>150</AUT_EXPERIENCE>
              </AUTHOR>
            </ROOT>

and compare to this expected result to check that the name of Author changed and that Author with id 2 was deleted

            <Root>
              <AUTHOR>
                <AUT_ID>1</AUT_ID>
                <AUT_FIRSTNAME>John</AUT_FIRSTNAME>
                <AUT_LASTNAME>Doe</AUT_LASTNAME>
                <AUT_EXPERIENCE>12</AUT_EXPERIENCE>
              </AUTHOR>             
            </ROOT>

Then this project might be interesting for you

At the time of writing the code works, but with some limitations and the documentation has to be written. But basically what this project provides is the ability to create a context from XML input files and compare it to XML expected output files. all that without your code hitting your database.(all in memory)

for more information check the project home page : CExtensions-Net

this project is based on some other opensource project like Effort and CompareNETObjects.