ormlite-servicestack

ServiceStack auto query global filter

青春壹個敷衍的年華 提交于 2019-12-25 04:44:09
问题 I'm looking at using ServiceStack's AutoQuery feature and I have some basic queries working. However I'd like to implement a global filter since I have a multi-tenanted database, e.g., All queries should be appended with the criteria CustomerId = Session.CustomerId What would be the best way to do this? 回答1: You could potentially use a custom AutoQuery base class for this to append the custom filter to each query, e.g: public abstract class MyAutoQueryServiceBase : AutoQueryServiceBase {

ServiceStack Ormlite UpdateNonDefaults for nullable type field

拟墨画扇 提交于 2019-12-25 04:16:07
问题 Please refer UpdateNonDefaults is ignoring boolean parameters set to false 回答1: bool properties are now always included in UpdateNonDefaults() with this commit which will let you do the following: public class Poco { public int Id { get; set; } public bool Bool { get; set; } } var db = OpenDbConnection(); db.DropAndCreateTable<Poco>(); db.Insert(new Poco { Id = 1, Bool = true }); db.UpdateNonDefaults(new Poco { Bool = false }, x => x.Id == 1); var row = db.SingleById<Poco>(1); row.Bool //

Selecting a subset of data in ServiceStack.OrmLite

我们两清 提交于 2019-12-24 03:26:06
问题 Is there any way to return a subset of a table in ServiceStack.OrmLite? Something like: public class MyStuff { public Guid Id { get; set; } public string Name { get; set; } public byte[] Data { get; set; } // Some large blob, which is not desired in the list } var somestuff = db.Select<MyStuff>(x => new { Id = x.Id, Name = x.Name }); I am really hoping to avoid manual stuff, like "select blabla from somewhere"... 回答1: I had that exact same problem. Here is what I did: public class MyStuff {

ServiceStack ORMLite not deserializing JSON stored in DB text field

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 02:33:39
问题 I have some telemetry data that was stored in a text field as JSON. I'm attempting to reverse-engineer POCOs to seamlessly extract and present that data without having to do any post-processing ForEach loops. When I attempt to manually parse the JSON string in the data field, it works. When I am selecting via ORMLite, it comes back with the default object. What am I missing? Works string x = "{\"alive\":true,\"paperStatus\":\"0:NoIssue\"}"; var telemetry = JsonSerializer.DeserializeFromString

ServiceStack Ormlite and RowVersion support

岁酱吖の 提交于 2019-12-24 00:43:27
问题 What is the easiest way to support sql server rowversion during update? I tried this: db.UpdateOnly(u, f => new { f.Name, f.Description, f.Modified, f.ModifiedBy }, f => f.Version == u.Version && f.Id == u.Id); but that fails miserably because it compares version as a Varchar(8000) , go figure. Not exactly the same but still a ServiceStack and OrmLite question: What is the best way to eager load related entity descriptions? I've seen this but noticed the Join changeset being checked in? This

How to Create Unique Constraint with Multiple Columns using ServiceStack.OrmLite?

假如想象 提交于 2019-12-23 20:12:38
问题 How does one create a unique constraint with ServiceStack.OrmLite (using attributes, hopefully)? The documentation shows how to create a unique constraint only on a single column: ServiceStack.OrmLite Docs If it helps, I am using ServiceStack.OrmLite.SqlServer . 回答1: Service Stack appears to have a CompositeIndex attribute which takes multiple field names. Here's a look at the constructors... CompositeIndexAttribute(params string[] fieldNames); CompositeIndexAttribute(bool unique, params

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

守給你的承諾、 提交于 2019-12-23 07:47:31
问题 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 updating the nuget packages, clean and rebuild the project, etc and none of them works. System.InvalidProgramException was caught _HResult=-2146233030 _message=JIT Compiler encountered an internal limitation. HResult=-2146233030 IsTransient=false

How do I execute a SQL statement with parameters in ServiceStack.OrmLite?

对着背影说爱祢 提交于 2019-12-23 06:41:39
问题 I want to execute SQL statement with paraemeters in ServiceStack ormlite String.Format("SELECT OBJECT_ID(@name)", name); I want the best way. 回答1: If you need the POCO result you can use: List<Person> results = db.SqlList<Person>("SELECT * FROM Person WHERE Age < @age", new { age=50}); Reference: https://github.com/ServiceStack/ServiceStack.OrmLite#typed-sqlexpressions-with-custom-sql-apis 回答2: You can use SqlScalar<T> where T is int . Then simply pass an anonymous object with your parameter.

SQL Server specific types support for OrmLite

别说谁变了你拦得住时间么 提交于 2019-12-22 01:42:59
问题 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 files to modify and any hints how to proceed? EDIT : Here is a better illustration of the problem. I have the following class: public class MyClass { public int Id { get; set; } public SqlHierarchyId HierarchyId { get; set; } } SqlHierarchyId is a

How to perform a more complex query with AutoQuery

霸气de小男生 提交于 2019-12-22 01:03:20
问题 Given the following definitions from a ServiceStack endpoint: public class LoanQueue { public int LoanId { get; set; } public DateTime Submitted { get; set; } public DateTime Funded { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Fico { get; set; } public int Fraud { get; set; } public int CDS { get; set; } public int IDA { get; set; } public string Income { get; set; } public string Liabilities { get; set; } public string Agent { get; set;