Starcounter Q&A list

More than a month passed since I have started to work on Starcounter project.

During this time I have learnt a lot of new and cool features about the Web, but the most exciting thing is Starcounter itself.

In the last five years I have finished a couple of projects in php, c# win forms and android, but the most used technology was asp.net mvc + entity framework. This is why it took me some time to adapt to Starcounter and stop trying to make it work same or similar as asp.net works. In this short article I put together some of the questions asp.net developers might ask.

Starcounter Q&A

What is Starcounter and Polyjuice?
Starcounter is very fast database with native support of c# language. Polyjuice is a set of useful features for developing web applications. This is a very short answer, visit official websites to read more: http://www.starcounter.com/, http://starcounter.io/, https://github.com/Polyjuice/.
What tools do I need to develop Starcounter application?
Starcounter application is a .net c# console application. You can develop applications with text editor and .net c# compiler.
Starcounter also has project templates for Visual Studio 2012/2013/2015, which makes development even easier.
Does Starcounter support debugging in Visual Studio?
Yes, you can debug your Starcounter applications in Visual Studio.
Can I use Starcounter without Polyjuice?
Yes, you can use Starcounter to develop your own web-application without Polyjuice.
Can I use Polyjucie without Starcounter?
Polyjuice has been developed to use with Starcounter, but you may use some of the html custom elements in your own project.
Can I develop console or desktop applications with Starcounter?
Starcounter application itself is a c# console application, but it should be started in scope of SC database. Currently, only web-applications supported.
Why should I even consider using Starcounter instead of well-known MS-SQL Server or MySql Server?
For developers: If you get tired of slow performance, complex stored procedures and triggers, application logic spread among client side, server side, and database side, then you should check out Starcounter, because it solves all of those problems.
For consumers: If you have a large and complex websystem or saas service, and you have to buy more and more servers to maintain competitive performance, then you should consider replacing all of your servers with one Starcounter server.
Is there any ORM like Entity Framework for Starcounter?
Starcounter does not require any specific ORM, the tables are defined by c# classes. Something similar to Entity Framework code first. However, it doesn’t translate objects to SQL like EF does, and this doesn’t bring overhead and need for thin profiling.
How to create primary key in Starcounter?
Each Starcounter db class has ObjectId property, which is primary key.
How to create foreign keys in Starcounter?
You have to define navigation properties in your classes, and Starcounter will do all of the foreign keys for you.
Is there navigation properties in Starcounter like in Entity Framework?
Yes, Starcounter db classes fully support navigation properties.
Does Starcounter support Views?
Starcounter does not require Views, because db classes may contain computed properties.
For example, we have class OrderItem with Price & Quantity properties. In traditional sql we may execute query like SELECT ID, Price, Quantity, Price * Quantity AS Total or create such View to select all required information about order items. In Starcounter this is done by defining Total property of OrderItem class.
public decimal Total { 
    get { 
        return this.Price * this.Quantity;
    }
}
Such properties are accessible everywhere, including sql queries.
Does Starcounter support multi-column indexes?
Yes, you can create multi-column indexes with sql.
Does Starcounter support multi-column foreign keys?
There is no multi-column foreign keys in Starcounter, but there is a solution to archive the same functionality. First, you have to define navigation property, which selects foreign key value based on two, three or many columns of your entity. Second, create an index for those properties.
Can I connect to multiply databases from one application?
No. If you need to access several database from one application, you will need to develop an API application, which will run inside all of the required databases, and then access the databases through the API application.
Does Starcounter support stored procedures and triggers, how to deal with very complex queries?
Starcounter does not require and does not support stored procedures or triggers. Starcounter has different architecture and it is much faster to execute complex logic from c# code than complex sql queries.
Does Starcounter support transactions?
Yes, Starcounter fully support transactions, moreover any database operation except select should be executed in a transaction.
There are two different transaction types, read more here: https://github.com/Starcounter/Starcounter/wiki/Transactions.
How Starcounter deals with locks?
There is no locks in Starcounter. Each transaction has its own copy of database, if the database was changed while transaction execution, then a new copy of database will be created and the transaction will be executed again.
Important to know: Starcounter transactions may contain any c# code, not only database access.
For example, we have table Orders and the row should be inserted only if there is enough products in stock for the order. The check logic and insert statement should be both inside a transaction.
How and when should I cache db execution result?
Starcounter database data already stored in memory, you might consider it as “cached”, that is why you don’t need to do any manual caching. Access to database require fewer resources than caching execution result.
What makes Starcounter + Polyjuice unique?
Starcounter + Polyjuice is the next step from MVC + MVVM.
Traditional asp.net mvc + knockout.js/angular.js application has server side model, server side view, and client side view-model. Client side view-model may contain its own client side logic and may or may not be the same as server side model.
Polyjuice applications share the same model for server and client side. All model changes are synchronized with json+patch requests. Polyjuice application does not have any client side logic, this makes it more secure and easier to maintain.
How would look typical add new database row scenario in Starcounter?
Let’s first see how it works in a traditional MVC application:
  1. User requests a url: /Products/Create.
  2. The Products controller executes Create action.
  3. Create action returns html with a form.
    1. The html page pay may contain client side MVVM library such as knockout.js or angular.js.
  4. User inputs data.
  5. User submits the form with data.
    1. The form may be submitted with an ajax request.
  6. The Products controller decodes passed form values into a Product object.
  7. The Products controller executes HttpPost Create action.
  8. The Create action validates and saves the Product.
  9. The Create action responds to client with another html or redirect result.
Now let’s see how it works in Starcounter:
  1. User requests a url: /Products/Create.
  2. The Products/Create handler creates ProductsPage view model.
  3. The handler responds to client with the view model’s html and data.
  4. User inputs data. The server side view model is automatically populated by json+patch request and validated on the fly.
  5. User presses Save button. Note, that instead of sending entire Product object to the server, we send only Save button click trigger, which means much faster response time.
  6. The view model commits current transaction and responds with another view model.
What Polyjuice is all about?
Polyjuice tends to use most recent and most exciting features of the Web, and this is of course webcomponents. If you are not yet familiar with webcomponents, then you should definitely go and check theirs website: http://webcomponents.org/.
What client side libraries does Prolyjuice use?
Polyjuice uses Polymer as javascript framework and bootswatch as css framework.
Can I use jquery and other custom javascript libraries?
Yes, you can use any JavaScript library you like, but this is not recommended.
Can I use third-party c# libraries in Starcounter application?
Yes, you can install NuGet package or reference local dll in your project. The only thing you have to do is add the dll to Weaver ignore list. Read more here: https://github.com/Starcounter/Starcounter/wiki/Weaver.
In Entity Framework we have EntityState (Added, Deleted, Detached, Modified, Unchanged) property of an object, is there such property in SC?
Unfortunately, but there is no such property.
Do this all work under all browsers?
No, unfortunately not. Webcomponents is a very new technology, which is fully supported by Google Chrome so far.
How to back up and restore Starcounter database?
Starcounter does not yet have GUI for this task, but you can unload and restore your database using staradmin console commands. Read more here: https://github.com/Starcounter/Starcounter/wiki/Reloading-database-between-Starcounter-versions.
Are there any migration tool from MS-SQL, MySql to Starcounter?
No, there is no such tool yet, but we are planning it.
Then what is the best way to migrate my ms-sql server db to Starcounter?
The easiest way would be to add Entity Framework model into your Starcounter application and copy your data from the old database to the new one.
Starcounter does not use App.config file, that is why you have to specify Entity Connection string in your code.
How do I override OnPropertyChanged, OnInserted, OnUpdated, OnDeleted methods of a db class?
This feature is not yet implemented, you can see the progress on this page: https://github.com/Starcounter/Starcounter/issues/2235.
Why all foreign key constrains are nullable? How can I change that?
Unfortunately, but null check constraint is not yet supported. You have to manually check your objects before saving them.
Are there cascade actions on update/delete?
There is no such features in Starcounter, but you can define function OnDelete in your db class, which executes before the object deleted from database.
How to use Session in Starcounter?
There is no absolute copy of asp.net session in starcounter. Starcounter’s session is related to a specific view model and can be used during lifetime of the view model. Read more here https://github.com/Starcounter/Starcounter/wiki/Sessions-and-server-side-JSON.
Can I use linq instead of writing raw sql queries?
No, Starcounter does not yet support linq queries.
My absolutely correct sql query rises an exception, why?
Starcounter does not support all sql operators. Try to simplify your query, escape table/property names with "", remove trailing ;, and post an issue on github if no success.
My application fails with a strange exception, why?
This may happen due some unexpected exception, try some of the next suggestions.
Make sure that ports 8080 and 8181 are free.
Kill all Starcounter processes by executing “staradmin kill all” command and start again.
Check administration log and see if there are any more information about the exception.
Make sure that you have valid working directory, read more here: https://github.com/Starcounter/Starcounter/wiki/Serving-static-content.
Investigate your code and remove suspicious lines.
Okay, how do I get started then?
Well, I am very happy that you are still here!
Download latest Starcounter Polyjucie edition nighty build from this page: http://downloads.starcounter.com/download or directly by this url: http://downloads.starcounter.com/download/Polyjuice/NextNightlyBuilds/latest.
Go to WiKi page to create your first Hello World application: https://github.com/Starcounter/Starcounter/wiki/Creating-a-Hello-World-application.
Clone demo application and see how it works: https://github.com/Starcounter/InvoiceDemo.
Ask me any question you came across and I will answer you asap!
Written by on
Views: 1666 Comments: 2
Mark on 27 January 2017 15:37 says

I'm playing arround wuith StarCounter and I'm very impressed by it. I'm using VS2015 update3 (as administrator) on Win10 and I'm using the VS extension. I have the localhost server running and can F5 the code.

I completed the first few steps of the HelloWorld tutorial but it seems that my changes to my .json definition are not propagated into the view (PersonJson.html). I understand from the tutorial that this is automatic. I'm pretty sure there's no typo. Also, when I manually change the labels (text) into an input (using the $ and the ::input syntax) the view does not change into an INPUT tag. When I manually add the INPUT tag in the view, the input fields work but the button still does not fire.

When I download the HelloWOrld app from GitHub that one works.

I suspect the VS extension is not working as expected.

Const on 27 January 2017 15:56 says

Mark, hi! It is nice to see you playing with Starcounter.

It is very difficult to understand your problem from the description. Could you please push the entire project to GitHub and share with me?