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?
Asked
Active
Viewed 73 times
0

Aniko Litvanyi
- 2,109
- 1
- 21
- 25

Le Minh Hao
- 13
- 4
-
Are you sure you want to use custom tables and columns? It would involve more coding than simply migrating the data to the Content Repository in SenseNet. That is the best solution in 99.99% of the cases :). You can import stuff into the SN repo with a few lines of code (let me know if you need an example), than you'll have all the benefits (like searching and permissions). – Miklós Tóth Oct 30 '16 at 09:08
-
There are only a few exceptional cases when it makes sense to keep custom tables - like when another app still wants to add or read records there - but even than there are better solutions (like synchronizing instead of using the same tables directly). Can you please add some examples or details on why do you plan to have custom tables? – Miklós Tóth Oct 30 '16 at 09:08
-
When you say "table", do you mean a custom SQL table, or custom Sensenet content? – Thane Plummer Apr 17 '17 at 02:18
1 Answers
2
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:
- Define content types in SenseNet for every entity type you have in your existing db (in the example below this is the Car type).
- 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).
- 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.");
}
}
}
}

Miklós Tóth
- 1,490
- 13
- 19