基于1.2 Raven Studio的方式并将代码移植到Windows控制台,我已经实现了我认为删除数据库(raven作为服务运行)的正确方法.
static class Program
{
static void Main(string[] args)
{
try
{
using (var store = new DocumentStore { ConnectionStringName = "RavenDB" }.Initialize())
{
var metadata = new RavenJObject();
var factory = store.JsonRequestFactory;
const string url = "http://localhost:8080/admin/databases/raven-products?hard-delete=true";
var credentials = CredentialCache.DefaultCredentials;
var convention = new DocumentConvention();
var requestParams = new CreateHttpJsonRequestParams(store.DatabaseCommands, url, "DELETE", metadata, credentials, convention);
var request = factory.CreateHttpJsonRequest(requestParams);
request.ExecuteRequest();
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press any key..");
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
执行此代码时,会引发以下异常.
System.Net.WebException:远程服务器返回错误:(401)未经授权.在System.Net.HttpWebRequest.GetResponse()at …
检查服务端点的请求标头的最佳方法是什么?
ContactService : Service
Run Code Online (Sandbox Code Playgroud)
阅读此https://github.com/ServiceStack/ServiceStack/wiki/Access-HTTP-specific-features-in-services我很好奇获得接口的首选方式.
谢谢你,斯蒂芬
简单的问题我猜,但是我花了一个小时试图让我的控制器的基类通过属性注入注入一些服务.这些属性首先受到作用域保护,但是一旦我将范围更改为公共工作,对象就会保持返回null.反正有没有保护属性并使IoC工作?
这是我的设置.
public class BaseController : Controller
{
[Inject]
protected LoggingInterface.ILogger<BaseController> Logger { set; get; }
[Inject]
protected IRepository Repository { set; get; }
protected override void OnAuthorization(AuthorizationContext filterContext)
{
....
base.OnAuthorization(filterContext);
}
}
Run Code Online (Sandbox Code Playgroud)
和NinjectMVC3 App_Start中的boot-strapper
private static void RegisterServices(IKernel kernel)
{
kernel.Bind(typeof(LoggingInterface.ILogger<>)).To(typeof(Log4NetLogger<>));
kernel.Bind<IRepository>().To<Repository>();
kernel.Bind<IUserService>().To<UserService>();
}
Run Code Online (Sandbox Code Playgroud)
谢谢你,斯蒂芬
我有一个与EF一起使用的对象,它有一个Bar的导航属性,它是一对多的,但应该是一对一的.无论如何,当我查询Foo时,我也想从Bar集合中获取第一个也是唯一一个项目,并将这些项目映射到一个扁平的Biz Dto,我将如何去做呢?
var result = (from c in ctx.Foo
where c.Bar.Any(cs => cs.LOGINNAME == username && cs.PASSWORD == password)
select c).First();
Run Code Online (Sandbox Code Playgroud)
然后在我的AutoMapper配置中,我创建了一个看起来像????的地图
Mapper.CreateMap<Foo, Biz>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.CLIENTID))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Bar.FirstOrDefault???))
Run Code Online (Sandbox Code Playgroud)
谢谢你,斯蒂芬
这是例外,现在完全让我的生活很痛苦。不知道发生了什么变化,但数据库位于 MVC3 站点的 App_Data 文件夹中。该网站托管在 IIS 7.5 中,作为默认网站。
任何解决问题的建议都将受到欢迎。
编辑..问题可能或多或少与我的控制器代码在抛出异常后没有清理有关,因此没有在文档会话上调用 dispose
Line 30: instance = new EmbeddableDocumentStore { ConnectionStringName = "RavenDB" };
Line 31: instance.Conventions.IdentityPartsSeparator = "-";
Line 32: instance.Initialize();
[EsentFileAccessDeniedException: Cannot access file, the file is locked or in use]
Microsoft.Isam.Esent.Interop.Api.Check(Int32 err) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:2739
Microsoft.Isam.Esent.Interop.Api.JetInit(JET_INSTANCE& instance) in C:\Work\ravendb\SharedLibs\Sources\managedesent-61618\EsentInterop\Api.cs:131
Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:207
[InvalidOperationException: Could not open transactional storage: C:\code\BE\Com.BuyEfficient\Com.BuyEfficient.Web\App_Data\ravendata\Data]
Raven.Storage.Esent.TransactionalStorage.Initialize(IUuidGenerator uuidGenerator) in c:\Builds\RavenDB-Stable\Raven.Storage.Esent\TransactionalStorage.cs:220
Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:156
Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal() in c:\Builds\RavenDB-Stable\Raven.Client.Embedded\EmbeddableDocumentStore.cs:143
Raven.Client.Document.DocumentStore.Initialize() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\DocumentStore.cs:483
Com.BuyEfficient.Web.Infrastructure.DataDocumentStore.Initialize() in C:\code\BE\Com.BuyEfficient\Com.BuyEfficient.Web\Infrastructure\DataDocumentStore.cs:32
Com.BuyEfficient.Web.App_Start.Services.PreStart() in C:\code\BE\Com.BuyEfficient\Com.BuyEfficient.Web\App_Start\Services.cs:25 …Run Code Online (Sandbox Code Playgroud) 如此简单但我找不到任何可以解释确切位置的信息或示例.我在这一点上猜测它应该在Configure方法中.
谢谢你,斯蒂芬
全球
public class AppHost : AppHostBase
{
public AppHost() : base("Web Services", typeof(ContactsService).Assembly) { }
public override void Configure(Container container)
{
//Set JSON web services to return idiomatic JSON camelCase properties
ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
//Show StackTrace in Web Service Exceptions
SetConfig(new EndpointHostConfig { DebugMode = true });
//Register any dependencies you want injected into your services
container.Register<ICacheClient>(new MemoryCacheClient());
/* // Redis
container.Register<IRedisClientsManager>(c => new PooledRedisClientManager());
container.Register<IRepository>(c => new Repository(c.Resolve<IRedisClientsManager>()));*/
container.Register<IRepository>(new Repository());
container.Register<IBusinessService>(new BusinessService());
//Configure Custom User Defined REST …Run Code Online (Sandbox Code Playgroud) 由于所述文件的大小和复杂性,我已经开始将我的应用程序分解为单独的文件,完全基于angular-seed项目完成它的方式.
在这个重新分解过程中,我遇到了原始控制器构造方式的问题.其中一些,将注入模态对话框的那些被创建为实例.
var firstInstanceCtrl = ['$scope', function($scope) { code... } ];
var secondInstanceCtrl = ['$scope', function($scope) { code... } ];
Run Code Online (Sandbox Code Playgroud)
并以这种方式在我的'主'控制器中使用
$scope.buttonClick = function (row) {
var viewModel = {};
var modalInstance = $modal.open({
backdrop: 'static',
windowClass: 'modal-wide',
templateUrl: 'modalFirst.html',
controller: firstInstanceCtrl,
resolve: {
viewModel: function () {
return viewModel;
}
}
});
modalInstance.result.then(function () {}, function () { });
};
Run Code Online (Sandbox Code Playgroud)
但是,现在注册控制器的方式,我没有看到如何获得实例的方法,例如
angular.module('myApp.controllers', []).
controller('firstInstanceCtrl', [function() {
}])
.controller('secondInstanceCtrl', [function() {
}]);
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,"如何在主控制器内部获得子控制器的实例?"
有人可以解释一下"_"的价值是什么吗?这就是fiddler为我的MVC 3页面显示的内容,该页面在客户端上有一个jQuery ajax调用.
GET/Services/GetFoodDescriptionsLookup(100)?_ = 1291727469299 HTTP/1.1
当URL以这种方式构造时,我不会收到任何数据,但如果我输入
GET/Services/GetFoodDescriptionsLookup(100)
这工作..
谢谢你,斯蒂芬
我想知道什么是获取搜索记录总数的最佳方法,同时返回Nth 128记录块数据段,这似乎是RavenDb运行时强加的上限.
例如,给定此查询,我还需要知道记录的总数.
var bookmarks = session.Query<Bookmark>()
.OrderByDescending(i => i.DateCreated)
.Skip(pageCount * (pageNumber – 1))
.Take(pageCount)
.ToList();
Run Code Online (Sandbox Code Playgroud)
谢谢你,斯蒂芬
我正在使用Advanced.LuceneQuery例如
RavenQueryStatistics stats = null;
vm.Products = DocumentSession.Advanced.LuceneQuery<Product>("Products/Index")
.Statistics(out stats)
.Where(searchExpression)
.OrderBy(columnToSortBy)
.Skip((vm.PageIndex - 1) * vm.PageSize)
.Take(vm.PageSize)
.ToArray()
;
Run Code Online (Sandbox Code Playgroud)
用这个索引
public Products_Index()
{
Map = products => from p in products
select new
{
p.ItemNum,
p.BrandName,
p.ProductName,
p.Catalog,
p.UOM,
p.CasePack,
p.AveWeight,
p.CatalogId,
p.HasPicture,
p.INFO2,
p.IsOfflineSupplierItem,
p.IsRebateItem,
p.IsSpecialOrderItem,
p.IsSpecialPriceItem,
p.Price
};
Indexes.Add(x => x.INFO2, FieldIndexing.Analyzed);
Indexes.Add(x => x.CatalogId, FieldIndexing.Analyzed);
Indexes.Add(x => x.HasPicture, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsOfflineSupplierItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsRebateItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsSpecialOrderItem, FieldIndexing.Analyzed);
Indexes.Add(x => x.IsSpecialPriceItem, FieldIndexing.Analyzed);
Indexes.Add(x …Run Code Online (Sandbox Code Playgroud) ravendb ×4
asp.net ×2
servicestack ×2
.net ×1
angularjs ×1
asp.net-mvc ×1
automapper ×1
iis-7.5 ×1
javascript ×1
jquery ×1
ninject ×1