Coder Social home page Coder Social logo

azure-table-storage-repository-pattern's Introduction

Azure Table Storage Repository

Move a existing POCO model to azure tables storage or just easy manage your tables from C#.

License: Not Decided, do with it as you see fit. Its a prerelease. Still playing alittle with the ideas of combining repositories for poco classes and ITableEntity Derived Classes.

azure-table-storage-repository-pattern's People

Contributors

pksorensen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

azure-table-storage-repository-pattern's Issues

Partition and Row Key's from the base class retrieved as Nulls

Accessing Partition and Row Key properties of the base class always returns null. Look at the below sample:

Here is the Product class:

public class Product : TableEntity
{
        public int ProductId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string ImageName { get; set; }
        public string Store { get; set; }
        public string Category { get; set; }
}

Here is the ProductContext class:

public class ProductContext : TableStorageContext
{
        private static IConfiguration _config;

        public ProductContext(IConfiguration config) : base(CloudStorageAccount.Parse(config["Data:DefaultConnection:StorageConnectionString"]))
        {
            _config = config;
            this.InsertionMode = InsertionMode.AddOrMerge;
            Table.SetInitializer(new CreateTablesIfNotExists<ProductContext>());
        }
        protected override void OnModelCreating(TableStorageModelBuilder modelbuilder)
        {
            modelbuilder.Entity<Product>()
                .HasKeys(pk => pk.Category, rk => string.Format("{0}_{1}", rk.Store.ToLower(), rk.ProductId))
                .ToTable(_config["Data:CloudTables:Product"]);

            base.OnModelCreating(modelbuilder);
        }
        public ITableRepository<Product> Products { get; set; }
}

Now, if you have a function like below:

public IEnumerable<Product> GetProducts(string category, int pageSize, int pageNumber, string orderBy)
{
         var context = new ProductContext(_config);
         var products = (from f in context.Products
                            where f.PartitionKey == category
                            select f).ToArray();
         return products;
}

In the above function, every single element within products has a NULL value in the following base class properties:

products[0].PartitionKey -> NULL
products[0].RowKey -> NULL
products[0].Timestamp -> NULL

Any ideas?

Partition and Row Key mapping to corresponding properties does not work with KeySeparator value. It always splits the properties by the first underscore

Hello, I have one more issue for ya!!

In an example of UnitTest5.cs

If you have an underscore in the one of property values that form a composite Row key, for example:

...
protected override void OnModelCreating(TableStorageModelBuilder modelbuilder)
{
    modelbuilder.Entity<Product>()
    .HasKeys(pk => pk.Category, rk =>new {  rk.Store, rk.ProductId})
    //   .HasKeys(pk => pk.Category,rk=>string.Format("{0}_{1}", rk.Store.ToLower(), rk.ProductId))              
    .ToTable("unittest5");

    base.OnModelCreating(modelbuilder);
}
...
var cat = "test";
            var ctx = new ProductContext();
            ctx.Products.Add(new Product
            {
                ProductId = 1,
                Name = "MyName",
                ImageName = "atest",
                Category = cat,
                Description = "adsad",
                Store = "test_abc",
            });
            ctx.SaveChangesAsync().Wait();

            var products = (from f in ctx.Products
                            where f.Category == cat
                            select f).ToArray();

In the above example Store = "test_abc" and ProductId = 1, so now the RowKey becomes
test_abc__1 [because if KeySeparator property is not set, it uses __ (two underscores) as default].

However, after running the following statement,

var products = (from f in ctx.Products
                            where f.Category == cat
                            select f).ToArray();

this is the output I get

products[0].Store = "test"
products[0].ProductId = "abc__1"

instead of getting

products[0].Store = "test_abc"
products[0].ProductId = "1"

It somehow still uses the first underscore to de-construct the properties from a RowKey. It does that for PartitionKey as well. I have tried explicitly setting the KeySeparator = "|", it still won't split the property on KeySeparator value but only on first underscore.

Hope you can help. Thanks.

Doesn't work with "WindowsAzure.Storage" versions > "4.1.0"

Hello,

First of all, great package. Thanks for writing it. I have tried to incorporate it in my ASP.NET 5 solution, but it doesn't work if I reference WindowsAzure.Storage Versions greater than 4.1.0. It works perfectly with 4.1.0.

As you might know WindowsAzure.Storage is currently in 5.0.1-preview version and if you update your references, it would be great.

I installed it using Nuget (if that helps) just a few days back.

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.