Absolutely. You can simply add an [Ignore] attribute on the properties that are not part of your schema. From the documentation: Ignoring DTO Properties You may use the [Ignore] attribute to denote DTO properties that are not fields in the table. This will force the SQL generation to ignore that...

By design OrmLite does not support marshalling to dynamic types, and expects resultsets to mapped to Typed POCO's. Although it does have specialized API's to map into loose-typed .NET collections: Dictionary<int, string> trackIdNamesMap = db.Dictionary<int, string>( "select Id, Name from Track") Dictionary<int, List<string>> albumTrackNames = db.Lookup<int, string>( "select AlbumId, Name...

I've just tried creating an AutoQuery Service with all the types you've provided under a custom MyNamespace and it's working as expected (in the latest of ServiceStack), i.e: Service definition: namespace MyNamespace { [Route("/visits/{VisitId}/services", Verbs = "GET")] public class ServicesAtVisit : QueryBase<VisitService, ServiceAtVisit>, IJoin<VisitService, Service> { public int VisitId {...

This is working as intended, the error message indicates that it couldn't find a static relationship that could be merged which negates the purpose of the Merge command - to merge related result sets. When there is no statically defined relationship that exists, this is clearly an error the developer...

The OrmLiteConnectionFactory should be registered as a singleton. You can then use it to create ADO.NET IDbConnection with: using (var db = dbFactory.OpenDbConnection()) { // } Once it's registered as a Singleton you could use a lazy property pattern that's like in the RepositoryBase class to simplify data access, e.g:...

There is no explicit support for Many to Many relationships in OrmLite, i.e. you would handle it by creating a Poco that maps to each RDBMS table and just save each as you would normally, see this previous answer for an example.

You can query this from OrmLite's ModelDefinition that's created for every POCO Table, e.g: var modelDef = typeof(Account).GetModelMetadata(); var tableName = modelDef.ModelName; var idName = modelDef.PrimaryKey.FieldName; Which in both cases will return the [Alias] if it exists....

The problem is that your class Inventory has a dictionary keyed by a complex class: public Dictionary<Item, int> Items { get; set; } However, according to the ServiceStack.Text documentation Any IDictionary is serialized into a standard JSON object, i.e: {"A":1,"B":2,"C":3,"D":4} Unfortunately your Item class cannot be represented as a simple...

Found this link that solved my problem: https://github.com/ServiceStackV3/mythz_blog/blob/master/pages/314.md Essentially I added a "Type" field to the ItemStep class, and set that when I create a new row (create the next step in the timeline). Then, when I retrieve that record, I call a method like "GetBody" in the referenced link...

Saving references on multi-nested structures isn't supported, but you're likely headed towards friction trying to convert a large JSON hierarchical document to a relational structure which has the potential to explode into multiple tables. A solution with less-friction is to just let OrmLite save nested complex types as schema-less text...

OrmLite's primarily a code-first ORM but does have T4 Templates to help with initially generating the code-first POCO's for existing database tables. Although after generating the POCO's, I'd be maintaining them (i.e. code-first) from that point forward....

To use Transactions in OrmLite you should use the OpenTransaction() API, e.g: using (var trans = db.OpenTransaction()) { //... } I've added a couple new API's to be able to use an OrmLite transaction with a raw ADO.NET IDbCommand in this commit. Use a managed OrmLite DB Command Use a...

The are several API's in OrmLite which rely on a primary key which will be either: A property annotated with the [PrimaryKey] attribute A property named Id Otherwise the first property is considered to be the primary key Some of OrmLite API's that rely on a primary key is: db.Update(entity)...

The way db.Delete() API works has been updated so that NULL fields are moved out of the parameterized queries and appended to the SQL filter so this should now work from v4.0.37+ that's now available on MyGet. You can also delete rows in OrmLite by PrimaryKey with: Db.DeleteById<TestTable>(entity.Id); For generic...

This is trivial now that OrmLite extension methods are now mockable by providing your own OrmLiteResultsFilter. E.g. this ResultsFilter below records every sql statement executed and inherts the behavior from OrmLiteResultsFilter to return empty results: public class CaptureSqlFilter : OrmLiteResultsFilter { public CaptureSqlFilter() { SqlFilter = CaptureSql; SqlStatements = new...

Adding an additional answer because really there were two issues. The real root seems to be with the stored procedure. I don't know why it wasn't consistently causing problems, but I rebuilt it using dynamic SQL to only include WHERE filters for parameters that are present. Originally, I had something...

Your error message sounds like you're mixing different versions of ServiceStack together. Try clearing your NuGet packages Cache. Alternatively you can try the most recent v4.0.34 packages on MyGet. As for non ASP.NET MVC Examples, most of the ServiceStack Live Demos are Single Page Apps that don't use ASP.NET MVC...

You can also use a SqlExpression, e.g: var rows = db.SqlList<ShipperTypeCount>( db.From<Shipper>() .GroupBy(x => x.ShipperTypeId) .OrderBy("Total") .Select(x => new { x.ShipperTypeId, Total = Sql.As(Sql.Count("*"), "Total") })); Alternatively instead of using a concrete POCO you can use a generic dictionary to populate a dictionary of ShipperTypeId => Total, e.g: var q...

After mythz explained to me the fact that if it doesn't map to your ormlite db it won't map to your resulting DTO later, i build a quick work around. Instead of returning my own response dto immediately in the following line: ARequest : QueryBase<Person, Result>, IJoin<Person, OtherThing> I just...

OrmLite's db.Load* API's is limited to loading 1-level depth of references. The Db.LoadReferences(instance) can be used to further fetch the disconnected POCO's references. You should also be mindful if loading references individually to avoid N+1 queries by loading them in a loop, i.e. when possible it's better to use a...

You should be able to use the new support for JOIN's in OrmLite's Typed SqlExpressions. It's best to use the latest v4.0.23 release on MyGet which includes improved support for selecting multiple columns across joined tables. With the new JOIN API's you can do what you need with something like:...

This issue is because you Foo doesn't have any columns to INSERT since Id is a autoincrementing primary key and Bar is a [Reference] property so no columns are saved so the INSERT SQL ends up looking like: INSERT INTO "Foo" () VALUES (); This would work if you Foo...

You should have a property like: [Reference] public ParentClass Parent { get; set; } on the ChildClass, and then you need to make sure that the property is properly filled up. You have the ParentId property on the child table in the database, so this shouldn't be any problem to...

Customizing Authenticate Service Response I would recommend that you always return a concrete class in ServiceStack Services (i.e. instead of an anonymous object) this helps with being able to generate metadata services for the DTO types and lets you deserialize the response in typed APIs. You should also consider adhering...

You still need to provide the foreign key that OrmLite can use to store the relationship, e.g. either on the Child/ForeignKey table: public class Order { [AutoIncrement] public int Id { get; set; } [Reference] public Item Item { get; set; } public string ProUserId { get; set; } public...

ServiceStack NuGet packages with a .Signed Suffix are strong-named, where other ServiceStack packages are not Strong named by default except for ServiceStack.Interfaces which is both Strong-Named and a pure PCL library for maximum accessibility. The ServiceStack download page maintains the list of available Signed packages....

First make sure your table has an auto incremented primary key. Second, Be careful with multiple inserts. You should call GetLastInsertedId directly after each insert. Under the hood in SQL it translates into SELECT SCOPE_IDENTITY() Your code should look more like the following: Db.Insert(new DeviceInfo.DeviceInfo { DeviceType = NewDevice.Type, HumanReadDevId...

You should normally use the Custom Sql API's like db.SqlList<T> when executing Custom SQL. If you want to use Custom SQL in a typed SqlExpression you should use the Unsafe* API's to by-pass any Custom SQL detection. But for the Select API of an SqlExpression you should only be adding...

View Last SQL Executed The easiest approach is to just print out the last SQL Statement that was executed, i.e: db.GetLastSql().Print(); This works well for most OrmLite API's which only execute a single SQL statement. But it wont show all SQL executed with OrmLite's higher-level API's like db.Save() which can...

The easiest way to get the new Id would be to have the insert return it by using selectIdentity. You can do something like this: var newId = Db.Insert(DeviceInfo, selectIdentity: true); newId would then contain the AutoIncremented Id that was generated. Another thing that draws my eye is that the...

I've just added implicit support for escaping wildcards in this commit which will now escape wildcards in the typed expressions that make use of LIKE, namely StartsWith, EndsWith and Contains, e.g: using (var db = OpenDbConnection()) { db.DropAndCreateTable<Poco>(); db.Insert(new Poco { Name = "a" }); db.Insert(new Poco { Name =...

EDIT - Now seeing the use case, the error is related to casting to the base type and the builder storing more than one column selector for the concrete BaseEntity. Consider adding an abstract JoinType class, and modifying the JoinType class so it will apply the join for the builder....

You shouldn't have nested transactions, rather than calling across services to perform DB operations you should extract shared logic out either using a separate shared Repository or re-usable extension methods: public static class DbExtensions { public static void SaveCaseModel(this IDbConnection db, CaseModel case) { db.Insert<Case>(case); db.SaveAllReferences<CaseModel>(case); } } Then your...