Le Minh Hao
Le Minh Hao

Reputation: 13

How to map colums in a table database in to Properties and relation with Fields

I'm studying Sensenet Framework and installed successfull on my computer, and now I'm developing our website based on this framework.
I read documents on wiki and understood relationship between Database <-> Properties <--> Fields <-> View (you can see the image in this link: http://wiki.sensenet.com/Field_-_for_Developers).
For suppose, if I added a new table in to Sensenet's database and desiderate show all datas inside this table to our page, but I don't know how to dev flow by this model: Database <=> Property <=> Field <=> View. ?
can you show steps to help me?

Upvotes: 0

Views: 75

Answers (1)

Mikl&#243;s T&#243;th
Mikl&#243;s T&#243;th

Reputation: 1511

Please consider storing your data in the SenseNet Content Repository instead of keeping custom tables in the database. It is much easier to work with regular content items and you will have all the feature the repo offers - e.g. indexing, permissions, and of course an existing UI. To do this, you will have to take the following steps:

  1. Define content types in SenseNet for every entity type you have in your existing db (in the example below this is the Car type).
  2. Create a container in the Content Repository where you want to put your content (in this case this is a Cars custom list under the default site).
  3. Create a command line tool using the SenseNet Client library to migrate your existing data to the Content Repository.

To see the example in detail, please check out this article:

The core of the example is really a few lines of code that actually saves content items into the Content Repository (through the REST API):

using (var conn = new SqlConnection(ConnectionString))
{
    await conn.OpenAsync();

    using (var command = new SqlCommand("SELECT * FROM Cars", conn))
    {
        using (var reader = await command.ExecuteReaderAsync())
        {
            while (await reader.ReadAsync())
            {
                var id = reader.GetInt32(0);
                var make = reader.GetString(1);
                var model = reader.GetString(2);
                var price = reader.GetInt32(3);

                // Build a new content in memory and fill custom metadata fields. No need to create
                // strongly typed objects here as the client Content is a dynamic type.
                // Parent path is a Content Repository path, e.g. "/Root/Sites/Default_Site/Cars"
                dynamic car = Content.CreateNew(ParentPath, "Car", "Car-" + id);
                car.Make = make;
                car.Model = model;
                car.Price = price;

                // save it through the HTTP REST API
                await car.SaveAsync();

                Console.WriteLine("Car-" + id + " saved.");
            }
        }
    }
}

Upvotes: 2

Related Questions