ADO.NET Data Services : Accessing Non-Relational Data

ADO.NET Data Services : Accessing Non-Relational Data

  • Comments 1

As you all know Astoria (Data Services) supports anything as backend. Not necessarily you need to have a Relational database to access data.

 

So if you talk about offline data like collection of an Object which may or may not come from an external entity (like XML) can also be exposed via Astoria.

 

I was trying to figure it out and a very uncommon error was occurring. Then Phani from Astoria product team helped me to resolve the issue. Thanks Phani.

 

namespace DataService_Blog

{

    /// <summary>

    /// Entity Structure

    /// </summary>

    [DataServiceKey("Id")]

    public class Person

    {      

        //Important that you need to have a property called "ID"

        //Or you need to specify the column for DataAccessKey like, [DataServiceKey("Id")]

        public int Id { get; set; }

        public string Name { get; set; }

        public DateTime DOB { get; set; }

    }

 

    /// <summary>

    /// Now you need to get IQueryable

    /// </summary>

    public class FamilyData

    {

        List<Person> family = new List<Person>();

        public FamilyData()

        {

            family = new List<Person>

            {

                new Person(){Id = 1, Name = "Debajyoti Ghosh", DOB = new DateTime(1946,1, 1)},

                new Person(){Id = 2, Name = "Sumitra Ghosh", DOB = new DateTime(1952,1, 1)},

                new Person(){Id = 3, Name = "Wriju Ghosh", DOB = new DateTime(1978,1, 1)},

                new Person(){Id = 4, Name = "Writam Ghosh", DOB = new DateTime(1985,1, 1)},

                new Person(){Id = 5, Name = "Sasyati Sanyal", DOB = new DateTime(1981,1, 1)},

            };

        }

 

        public IQueryable<Person> Family

        {

            get

            {             

                return family.AsQueryable<Person>();

            }

        }

    }

 

    /// <summary>

    /// Here is your Service

    /// </summary>

    public class DataS : DataService<FamilyData>

    {

        public static void InitializeService(IDataServiceConfiguration config)

        {

            config.SetEntitySetAccessRule("Family", EntitySetRights.All);

        }

    }

}

 

Namoskar!!!

Leave a Comment
  • Please add 1 and 1 and type the answer here:
  • Post