servicestack

ServiceStack.OrmLite equivalent of Single/SingleOrDefault from Entity Framework

谁说我不能喝 提交于 2019-12-12 05:28:14
问题 Currently when using OrmLite library from ServiceStack if I want single entity selected I do: AppUser user = db.First<AppUser>(q => q.Id == id); However since Single is more precise (obviously I want exception thrown if somehow multiple users with same id ended up in database) I was wondering if there is overload that I can use. Currently when I do db.Single I just get that overload with manual filtering: public static T SingleOrDefault<T>(this IDbConnection dbConn, string filter); 回答1: OK, I

ServiceStack: URL Re-writing with Self-Hosted application

江枫思渺然 提交于 2019-12-12 04:13:24
问题 I have a self-hosted application which has an index.html file at its root. When I run the application and go to localhost:8090 (app is hosted on this port) the URL looks like: http://localhost:8090/index.html . Is there anyway I can make the URL to just be: http://localhost:8090 when on the index.html page? Note I'm using V3 of ServiceStack 回答1: ServiceStack v4 In ServiceStack v4 I use a raw http handler to intercept the root. In your AppHost Configure method: public override void Configure

F# Multiple Attributes CLIMutable DataContract

血红的双手。 提交于 2019-12-12 03:59:13
问题 I am running into an issue with combining attributes when using ServiceStack.Redis with f#. Maybe I am thinking about this wrong but right now I'd like my type to be seralized to JSON but also passable to ServicvStack. The issue with f# types is that there is no default constructor and this the data added to my Redis instance is emtpy, well the record is there but none of the data inside it is there. Here is an example: open System open ServiceStack.Redis [<CLIMutable>] [<DataContract>] type

ServiceStack renders RequestBindingException via Razor template

只愿长相守 提交于 2019-12-12 03:28:25
问题 I have a simple DTO with just an Int inside: [Route("/cells/{Id}")] public class CellDetail { public int Id { get; set; } } Using a URL like /cells/abc gives med a RequestBindingException in JSON, but the HTML view is still rendered via my .cshtml file, which obviously fails due to @Model == null. Shouldn't it give a HTML error page instead? How does it even know which .cshtml view to select? 回答1: The Razor Page lets you access the Error Info about the Request in: object ModelError { get; } /

Deserializing Multidimensional array from JSON with ServiceStack fails

ぐ巨炮叔叔 提交于 2019-12-12 03:22:10
问题 I have an object with a single double[,] property, which was serialized using ServiceStack ToJson() method as follows: {"xy":[[-2.9774,-2.0682],[-1.1378,2.7118]]} However I cannot deserialize it back to my object type ( Parameters ) using "abovestring".FromJson<Parameters>() as it throws the following exception: System.Runtime.Serialization.SerializationException: Failed to set property 'xy' with '[[-2.9774,-2.0682],[-1.1378,2.7118]]' ---> System.FormatException: Input string was not in a

Deserialize CSV with CustomHeaders using ServiceStack.Text

对着背影说爱祢 提交于 2019-12-12 02:54:31
问题 I'm trying to use ServiceStack.Text for deserializing a csv file containing custom headers. var csv = "Col-1,Col-2" + Environment.NewLine + "Val1,Val2" + Environment.NewLine + "Val3,Val3" + Environment.NewLine; public class Line { public string Col1 { get; set; } public string Col2 { get; set; } } ServiceStack.Text.CsvConfig<Line>.CustomHeadersMap = new Dictionary<string, string> { {"Col1", "Col-1"}, {"Col2", "Col-2"} }; var r2 = ServiceStack.Text.CsvSerializer.DeserializeFromString<List<Line

Bulk create keys in Redis - ServiceStack C#

丶灬走出姿态 提交于 2019-12-12 02:22:59
问题 Is there any way to bulk-create keys ( SETS ) in " Redis ServiceStack client "? Of course, without putting for loop. There is one command in Redis which does this: MSET but, I couldn't find any implementation of this command in ServiceStack.Redis client. Ex: MSET key1 "val1" key2 "val2" UPDATE: @mythz suggested a way to create multiple SETS but with single member SETALL(). Additionally, I found a way to bulk add members to a single set by AddRangeToSet(string setId, List items) But, is there

ServiceStack AutoQuery - Simplify with Generic and Custom Attributes

房东的猫 提交于 2019-12-12 02:05:50
问题 This question comes from another to Simplify OrmLite with AutoQuery. ServiceStack AutoQuery allows all my different Get(AKindOfType dto) to share the same code, like below: (I have many models, like Company, my two more questions attempt to simplify the code further) // ====== Model.cs ======== [Route("/company/search")] public class QueryableCompany : QueryBase<Company> { public int? Id { get; set; } public string Company { get; set; } public int? CompanyNo { get; set; } public bool? Active

servicestack syncreply removed, not backwards compatible?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 01:14:05
问题 We're in the process of upgrading to servicestack v4 and noticed that the default "SyncReply" route was removed in favor of "Reply". We have customers who are actively using these endpoints in our services. What is the recommended way to achieve backwards compatibility for these customers, without having to manually register the routes for each content-type+service? 回答1: You can use v3 clients that point to a v4 server by using the UseNewPredefinedRoutes property, provided that the over-the

How can I set (override) all items in hash

不羁的心 提交于 2019-12-11 23:22:17
问题 I want to set all entries in Hash. (SetAllEntriesToHash) It must Clear all items in hash before running. It is opposite of GetAllEntriesFromHash. 回答1: You have a couple options here. 1) You could let ServiceStack take care of this for you by using the high level Redis API. public class Poco { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } } ... // Client var client = new RedisClient("localhost", 6379); // This will store the object for you