ormlite-servicestack

How to pass non-optional NULL parameters to a Stored Proc using OrmLite

浪子不回头ぞ 提交于 2019-12-10 10:28:24
问题 I'm using OrmLite against an existing SQL Server database that has published stored procedures for access. One of these SPs takes 3 int parameters, but expects that one or another will be null. However, none of the parameters are declared optional. Here's the code I've tried: using (IDbConnection scon = myFactory.OpenDbConnection()) { rowCount = scon.SqlScalar<int>("EXEC myProc @FileID, @FileTypeID, @POID", new { FileID = req.FileId, FileTypeID = (int?)null, POID = req.PoId, }); } But this

ServiceStack OrmLite How can I achieve automatic setting of foreign key/related properties?

拜拜、爱过 提交于 2019-12-10 09:30:25
问题 I have created the following example to test Foreign Keys and up to this point, it works well. What I would like to be able to do, is use this framework that I built to set the property of the relationship and have it Save the child object when the Parent is saved and automatically set the PrimaryKey and Foreign Key. The DataManager class exposes the Connection public class DataManager { DataManager() { OrmLiteConfig.DialectProvider = SqliteDialect.Provider; ConnectionString = SqliteFileDb;

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

筅森魡賤 提交于 2019-12-10 02:17:36
问题 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 way of doing it? Something like StringLength(Sql.VarcharMax) Thanks 回答1: Worked around the issue by doing the following if (!db.TableExists(typeof(Entity).Name)) { db.CreateTableIfNotExists<Entity>(); db.ExecuteSql("ALTER TABLE Entity ALTER COLUMN

ntext in ServiceStack.OrmLite

强颜欢笑 提交于 2019-12-08 19:21:10
问题 how can i have nText datatype in ServiceStack.OrmLite Code first ? public class Email { [AutoIncrement] public long ID { get; set; } public DateTime Date { get; set; } public string From { get; set; } public string Subject { get; set; } nText => public string Body { get; set; } } if i use string datatype , ormlite generate nVarchar(8000) in database i need more than 8000 character for data 回答1: You need to convert your Body type to byte[] from string for ServiceStack.OrmLite to use the

Why does the “Limit()” method no longer exist in the ServiceStack OrmLite v4?

浪子不回头ぞ 提交于 2019-12-08 12:06:55
问题 in ServiceStack OrmLite v3 you could do: var rows = db.Select<Employee>().Limit(10)); Or: var rows = db.Select<Employee>().Limit(5, 10)); // skips 5 then takes 10 However I cannot find these methods any longer in v4. I suppose I can do the following instead: var rows = db.SelectLazy<Employee>().Take(10); However how can I do a db.Select (not having to write direct SQL) which will translate to (in SQLite for example): SELECT * FROM Employee LIMIT 10; Also, is it possible to write an equivalent

Populating POCO's with ServiceStack.OrmLite

▼魔方 西西 提交于 2019-12-07 23:51:08
问题 Consider the following domain model: class Customer { int id {get;set} string Name {get;set} List<Contact> Contacts {get;set} } class Contact { int id {get;set} string FullName {get;set} List<PhoneNumber> {get;set} } class PhoneNumber { int id {get;set} PhoneType Type {get;set} string Number {get;set} } Customer, Contact & PhoneNumbers are separate entities in our DB. Any Suggestions as to how to populate a full customer with all its linked contacts and the contacts phone numbers in the most

Is it possible to create a cross-database query with ServiceStack ORMLite?

為{幸葍}努か 提交于 2019-12-07 18:42:04
问题 Pretty much summed up in the title. Trying to hit a table in one database and join it to a table in another database on the same server. I would have assumed an attribute for Database that I could decorate the POCO with, but do not see one that would be appropriate. Currently using this syntax: var result = db.Select<Model.Dto>( db.From<Data.Dto1>() .Join<Data.Dto2>(d1, d2) => d1.Id == d2.Id)); 回答1: There's no specific attribute for specifying an external database but in RDBMS's that support

Make ORMLite use proper serialization for structs

偶尔善良 提交于 2019-12-07 17:13:46
问题 tl;dr: I am registering a serializer and a deserializer on a struct. The serializer is not called, but the deserializer is. How can I fix this? It works properly on reference types, and doing JsConfig<Position>.TreatValueAsRefType = true; did not help either. Long version: I am storing two complex types using ORMLite: Position (a struct, from external library DotSpatial which we do not control) and Tuple. In order to be able to properly store/read them from the database, I defined their

How to LeftJoin to the same table twice using ServiceStack OrmLite?

*爱你&永不变心* 提交于 2019-12-07 14:29:40
问题 I have table structures that look like below: table Tenant: Id[PK], etc table Contact: Id[PK], FirstName, LastName etc table Sale: Id[PK], TenantId[FK], SellerId[FK], BuyerId[FK], etc SellerId is a FK to Contact.Id BuyerId is a FK to Contact.Id TenantId is a FK to Tenant.Id I want to use OrmLite to generate SQL similar to below: select sale.* , buyer.FirstName 'BuyerFirstName' , buyer.LastName 'BuyerLastName' , seller.FirstName 'SellerFirstName' , seller.LastName 'SellerLastName' from sale

OrmLite query to select some of the columns from each of 2 joined tables

拈花ヽ惹草 提交于 2019-12-07 06:22:56
问题 Following on from this comment, how can I do a ServiceStack OrmLite query that joins two or more tables and returns some of the columns from each of them? Using the OrmLite Does_only_populate_Select_fields_wildcard unit test as example, I'd like to do something like this: public class DeptEmployee { [PrimaryKey] public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } [References(typeof(Department2))] public int DepartmentId { get; set; }