Questions tagged [ormlite-servicestack]

ServiceStack.OrmLite is a convention-based, configuration-free lightweight ORM that uses standard POCO classes and Data Annotation attributes to infer its table schema.

Fast, Simple, Typed ORM for .NET

OrmLite provides a convenient, DRY, config-free, RDBMS-agnostic typed wrapper that retains a high affinity with SQL, exposing intuitive APIs that generate predictable SQL and maps cleanly to (DTO-friendly) disconnected POCO's. This approach makes easier to reason-about your data access making it obvious what SQL is getting executed at what time, whilst mitigating unexpected behavior, implicit N+1 queries and leaky data access prevalent in Heavy ORMs.

OrmLite was designed with a focus on the core objectives:

  • Provide a set of light-weight C# extension methods around .NET's impl-agnostic System.Data.* interfaces
  • Map a POCO class 1:1 to an RDBMS table, cleanly by conventions, without any attributes required.
  • Create/Drop DB Table schemas using nothing but POCO class definitions (IOTW a true code-first ORM)
  • Simplicity - typed, wrist friendly API for common data access patterns.
  • High performance - with support for indexes, text blobs, etc.
  • Expressive power and flexibility - with access to IDbCommand and raw SQL
  • Cross platform - supports multiple dbs (currently: Sql Server, Sqlite, MySql, PostgreSQL, Firebird) running on both .NET and Mono platforms.

In OrmLite: 1 Class = 1 Table. There should be no surprising or hidden behaviour, the Typed API that produces the Query doesn't impact how results get intuitively mapped to the returned POCO's which could be different to the POCO used to create the query, e.g. containing only a subset of the fields you want populated.

Any non-scalar properties (i.e. complex types) are text blobbed by default in a schema-less text field using any of the available pluggable text serializers. Support for POCO-friendly references is also available to provide a convenient API to persist related models. Effectively this allows you to create a table from any POCO type and it should persist as expected in a DB Table with columns for each of the classes 1st level public properties.

880 questions
22
votes
3 answers

How to retrieve auto-incremented Id in ServiceStack OrmLite?

For a table that has an identity: [AutoIncrement] public int Id { get; set;} When inserting a new row into the database, what is the best way to retrieve the Id of the object? For example: db.Insert<> (new User()); The value of the Id is…
Dylan
  • 1,919
  • 3
  • 27
  • 51
16
votes
1 answer

SQL Server specific types support for OrmLite

I just learned about a genius type that would simplify a lot of my work but it looks like my preferred ORM does not recognize it. Is there a workaround to let ServiceStack OrmLite recognize HierarchyId in SQL Server? Any suggestions about which…
Moslem Ben Dhaou
  • 6,897
  • 8
  • 62
  • 93
14
votes
1 answer

ServiceStack OrmLite with multiple Database Servers

I'm building an app around the servicestack framework and need to be able to access data in both Oracle and MS Sql Server. Is this possible using ORMLite, it seems that I can only set a single dialect for the App or have I missed something?
MikeT
  • 807
  • 10
  • 21
12
votes
1 answer

Eager loading with ormlite servicestack

This is entity framework: var department = _context.Departments .Include(dep => dep.Employees.Select(emp => emp.ContactTypes)) .SingleOrDefault(d => d.Id == departmentId); Here I expect one department to be returned…
Pascal
  • 12,265
  • 25
  • 103
  • 195
12
votes
1 answer

How to unit test ServiceStack?

I love SS but I'm scratching my head trying to unit test my business layer. I'm new to unit testing andmocking and been reading up on NSubstitute as this looks like a fun mocking layer. I have my file structure roughly like…
fractal
  • 1,649
  • 17
  • 31
12
votes
2 answers

Paging in servicestack ormlite

I am looking for a good way to implement paging in ormlite and I found another question, which has this snippet: var data = db.Select
(predicate).Skip((int) pageNumber).Take((int) pageSize).ToList(); Problem with the above is that it gets…
Ali
  • 1,256
  • 3
  • 15
  • 31
12
votes
1 answer

Using schema names with SQL Server & ServiceStack.OrmLite

Anyone know how to apply the correct Alias attribute to query tables with schema names? I have a table called accounts.register. I've tried using [Alias("accounts.register")] as the class decorator attribute for Register class but this doesn't…
Neil Dobson
  • 1,239
  • 1
  • 12
  • 24
11
votes
4 answers

Create a column with varchar(max) rather than varchar(8000)

How can I create a column in a table and specify it as varchar(max) when using servicestack ormlite? Currently I execute some sql after the table create to get what I want. I've seen the StringLength attribute but was wondering if there's a nicer…
Antony Denyer
  • 1,541
  • 1
  • 15
  • 31
11
votes
1 answer

Best practices of implementing unit of work and repository pattern using ServiceStack.ORMLite

Supposing that there are two repository interface : interface IFooRepository { void Delete(int id); } interface IBarRepository { void Delete(int id); } And an IUnitOfWork interface like : interface IUnitOfWork : IDisposable { void…
10
votes
2 answers

How to use Dapper in ServiceStack

Currently, I am using OrmLite for DB operations. I am also planning to use Dapper ORM, but can anyone point me how to integrate DapperORM in ServiceStack. Do I need to implement both IDbConnection and IDbConnectionFactory interfaces with Dapper and…
Sunny
  • 4,765
  • 5
  • 37
  • 72
10
votes
1 answer

ServiceStack OrmLite Sql Query Logging

As per the Service Stack Ormlite documentation. I should generate the sql query in debug mode. But, I am not able to see those queries. Simple code private static readonly string DataDirLoc = …
Mohit
  • 914
  • 4
  • 14
  • 28
9
votes
2 answers

Transactions in the Repository Pattern using ServiceStack.ORMLite

I'm implementing Repository Pattern using ServiceStack.ORMLite like this: public class MyRepository : IMyRepository { private IDbConnectionFactory DbConnectionFactory = null; public MyRepository(IDbConnectionFactory dbConnectionFactory) …
9
votes
6 answers

With OrmLite, is there a way to automatically update table schema when my POCO is modified?

Can OrmLite recognize differences between my POCO and my schema and automatically add (or remove) columns as necessary to force the schema to remain in sync with my POCO? If this ability doesn't exist, is there way for me to query the db for table…
TMc
  • 225
  • 4
  • 9
9
votes
2 answers

ServiceStack OrmLite - Handling Default and Computed columns

How exactly is ServiceStack OrmLite handling default and computed columns? Specifically I'm getting the error The column "PointsAvailable" cannot be modified because it is either a computed column or is the result of a UNION operator. This column…
John
  • 1,286
  • 2
  • 14
  • 22
8
votes
1 answer

ServiceStack Ormlite: System.InvalidProgramException JIT Compiler encountered an internal limitation

Hi i'm running ServiceStack with Ormlite and I encountered this error. Previously it is working fine. I'm not sure what I have changed that caused this error. I just used a simple db.Select() call and it throws this error. I tried various ways, like…
icube
  • 2,578
  • 1
  • 30
  • 63
1
2 3
58 59