This project is read-only.

Razor Repository

a razor repository engine to handle the database and custom classes bindings
no need to write sql scripts

Are there any limitations ? and if so Why? 

 as this project should had been to big - and i didn't want to make hard life for client which use the project this project with configuration there are few limitations

just to make clear - also those limitations can be expanded and fixed , just look at the source code - some of those already got a method which you just need to change in order to fix - if there would be high requested i might update this in the future to fix the limitations with config abilities or deeper sql queries.

Limitations List:

1. when posting - same as in ASP.NET MVC - the input control name fields should be the same as the posted model (that is if you are trying to use the asscilated binding method)
2. when saving into the database - the model name must be the same is the table name, means if you got a model called "Person" your table name should be also "Person"
3. Index key field should be called "Id". 
4. There should be only 1 .sdf file inside your App_Data folder 


copy Razor.cs and RazorLib folder into your App_Code folder.

Basic Use:

after we cleared the limitations - the use is pretty basic
you can choose to create a new instance of your model and fill the values by hand using Request[key]
or ... you can use Razor.GetModel<T>(); which would bind a model from the Request values

create your repository using

var repository = Razor.Repository();

afterwards please look at the repository methods

Method Description  Returns Example
All<T>() Returns all the objects of T model IEnumerable<dynamic> Person[] people = repository.All<Person>().ToArray();
Get<T>(int id) Gets an object by it's id T Person person = repository.Get<Person>(1);
Where<T>(string query) Gets models using where query string IEnumerable<dynamic>
Person[] people = repository.Where<Person>("Age > 20").ToArray();
Where<T>(string parm, object expectedValue) Gets models where parm = expectedValue IEnumerable<dynamic>
Person[] people = repository.Where<Person>("Age",20).ToArray(); // would return where age = 20
Contains<T>(string parm, object expectedValue) Gets models where parm.Contains(expectedValue) IEnumerable<dynamic> Person[] people = repository.Contains<Person>("Name","m").ToArray(); //would return where name contains 'm' character
Bigger<T>(string parm, object expectedValue) Gets models where parm is bigger than expected value IEnumerable<dynamic> Person[] people = repository.Bigger<Person>("Age",20).ToArray();
Smaller<T>(string parm, object expectedValue) Gets models where parm is smaller than expected value IEnumerable<dynamic> Person[] people = repository.Smaller<Person>("Age",20).ToArray();
Insert<T>(T entity) Insert T entity into database   repository.Insert<Person>(person);
Update<T>(T entity) Updates T entity with new values   repository.Update<Person>(person);
Delete<T>(int id) Deletes T entity where Id = id   repository.Delete<Person>(1);
Delete<T>(T entity) Deletes T entity   repository.Delete<Person>(person);

There are few bit more complex methods which you can use for more custom variations but those are the most usefull ones.

With the code files there is also an example project 

Last edited Nov 27, 2010 at 9:45 PM by Itayeng, version 2


No comments yet.