我最近在Fowler的PofEA中读到,一些数据库引擎允许您将RI检查推迟到事务结束.这可能在SQL Server中吗?
问题出现在某些情况下,我试图保存包含插入和删除的更改,确定执行操作以避免RI失败的正确顺序可能很棘手.我知道在交易结束时RI会很好,所以推迟这些检查似乎是理想的.
我正在尝试向ASP.NET Web API发送get请求并获取XML以在我的Android应用程序中解析它.当我通过Web浏览器尝试链接时它返回XML,但是当Android应用程序发送请求时它返回JSON.如何以仅发送XML的方式修复它?谢谢
我有一个我正在研究的ASP.NET WebApi项目.老板希望返回支持"部分响应",这意味着尽管数据模型可能包含50个字段,但客户端应该能够为响应请求特定字段.原因是如果他们实现例如列表他们根本不需要所有50个字段的开销,他们可能只想要名字,姓氏和Id来生成列表.到目前为止,我已经使用自定义合约解析器(DynamicContractResolver)实现了一个解决方案,这样当请求进入时,我通过OnActionExecuting方法中的过滤器(FieldListFilter)窥视它,并确定是否有一个名为"FieldList"的字段
一些示例代码
DynamicContractResolver.cs
protected override IList<JsonProperty> CreateProperties(Type type, Newtonsoft.Json.MemberSerialization memberSerialization)
{
List<String> fieldList = ConvertFieldStringToList();
IList<JsonProperty> properties = base.CreateProperties(type, memberSerialization);
if (fieldList.Count == 0)
{
return properties;
}
// If we have fields, check that FieldList is one of them.
if (!fieldList.Contains("FieldList"))
// If not then add it, FieldList must ALWAYS be a part of any non null field list.
fieldList.Add("FieldList");
if (!fieldList.Contains("Data"))
fieldList.Add("Data");
if (!fieldList.Contains("FilterText"))
fieldList.Add("FilterText");
if (!fieldList.Contains("PageNumber"))
fieldList.Add("PageNumber");
if (!fieldList.Contains("RecordsReturned"))
fieldList.Add("RecordsReturned");
if (!fieldList.Contains("RecordsFound"))
fieldList.Add("RecordsFound");
for (int ctr …Run Code Online (Sandbox Code Playgroud) 我通过nuget将ASP.NET 4 Web API帮助页面包安装到我的Web Api项目中.由于某种原因,它不会显示所有api端点.我有文档设置使用XML.不知道为什么会这样,任何帮助表示赞赏.
这是一个示例控制器
public class ProductController : BaseController
{
// GET api/Product/Get/5/43324
[AcceptVerbs("GET")]
public ApiProduct Get(int id, [FromUri]int productId)
{
//// logic
}
}
Run Code Online (Sandbox Code Playgroud)
路线
config.Routes.MapHttpRoute(
name: "api-info",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional, action = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试使用 Microsoft Graph API 从 SharePoint 文档库获取文件夹和文档。
\n\n如果我请求GET,https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/我会得到这个:
{\n "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",\n "value":[\n {\n "createdDateTime": "2019-09-05T07:09:49Z",\n "description": "",\n "id": "b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX",\n "lastModifiedDateTime": "2019-09-05T07:09:49Z",\n "name": "Documents",\n "webUrl": "https://mysite.sharepoint.com/sites/MyDocumentSite/Shared%20Documents",\n "driveType": "documentLibrary",\n "createdBy":{"user":{"displayName": "System Account" }},\n "lastModifiedBy":{"user":{"email": "me@myorganization.org", "id": "73f9990c-5c92-4839-8b13-XXXXXXXXXXXX", "displayName": "John Smith"\xe2\x80\xa6},\n "quota":{"deleted": 0, "remaining": 0, "total": 0, "used": 0}\n }\n ]\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但是,如果我尝试通过GET对该 id: 执行请求来访问该驱动器https://graph.microsoft.com/v1.0/sites/mysite.sharepoint.com:/sites/MyDocumentSite:/drives/b!wxh2ZWwoT0KKTdLRYjD5jvzjo8jkat5LgY3VyfgEqkv3YVg_XXXXXXXXXXXXXXXX,则会收到 BadRequest 错误:
{\n "error":{\n "code": "BadRequest",\n "message": "Url specified is invalid.",\n "innerError":{\n "request-id": "7c9eaf61-764f-4d72-abdb-ffa2fe868e90",\n "date": "2019-09-16T19:09:41"\n }\n …Run Code Online (Sandbox Code Playgroud) 我目前使用GetManifestResourceStream来访问嵌入式资源.资源的名称来自不区分大小写的外部源.有没有办法以不区分大小写的方式访问嵌入式资源?
我宁愿不必仅使用小写字母来命名所有嵌入式资源.
我想在我的控制器中使用以下模式:
API/{控制器}/{ID}/{收集}
示例: api/customers/123/addresses
但我想IQueryable Of T从相应的Get动作返回.我想要这样的东西(简化):
public IQueryable<????> GetCollection(int id, string collection)
{
switch(collection)
{
case "addresses":
return _addresses.AsQueryable();
break;
case "orders":
return _orders.AsQueryable();
break;
default:
throw new Exception(NotSupported);
}
}
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
推荐的方法是什么?
我一直在努力使用我的路由已经有一段时间了,经过几天尝试谷歌解决方案没有运气,我希望有人能够对我的问题有所启发.
我的WebApiConfig中有以下路由:
config.Routes.MapHttpRoute(
name: "AccountStuffId",
routeTemplate: "api/Account/{action}/{Id}",
defaults: new { controller = "Account", Id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "AccountStuffAlias",
routeTemplate: "api/Account/{action}/{Alias}",
defaults: new { controller = "Account", Alias = RouteParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
以及以下控制器方法:
[HttpGet]
public Account GetAccountById(string Id)
{
return null;
}
[HttpGet]
public Account GetAccountByAlias(string alias)
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
如果我打电话:
/API/Account/GetAccountById/stuff那么它正确调用GetAccountById.
但如果我打电话,/API/Account/GetAccountByAlias/stuff那么没有任何反应
显然,这里的顺序很重要,因为如果我在WebApiConfig中切换我的路由声明,那么/API/Account/GetAccountByAlias/stuff正确调用GetAccountByAlias,/API/Account/GetAccountById/stuff什么都不做.
这两个[HttpGet]装饰是我在谷歌上发现的一部分,但它们似乎没有解决问题.
有什么想法吗?我做了什么明显错误的事吗?
编辑:
当路由失败时,页面显示以下内容:
<Error>
<Message>
No HTTP resource was …Run Code Online (Sandbox Code Playgroud) asp.net-mvc asp.net-mvc-controller asp.net-web-api asp.net-web-api-routing
我将启动一个需要Web和桌面界面的项目.一个解决方案似乎是IdeaBlade(http://www.ideablade.com).任何使用它的人都可以描述它的局限性和优势吗?它可以测试吗?
谢谢,亚历克斯
您好我在asp.net WebApi中创建一个异常处理机制,我对如何创建返回的响应消息感到困惑.这是我的代码:
public class ExceptionHandlerAttribute : ExceptionFilterAttribute
{
public override void OnException(HttpActionExecutedContext actionExecutedContext)
{
actionExecutedContext.Request.CreateErrorResponse(HttpStatusCode.Accepted, new HttpError
{
{ "Message" , "I am error"},
{ "StatusCode" , "20"}
});
}
}
[AllowAnonymous]
[HttpPost]
[Validate]
public IHttpActionResult Register(UserModel userRegistrationModel)
{
throw new AccessDeniedException("message" , new Exception("inner exception"));
}
public class AccessDeniedException : BaseException
{
public AccessDeniedException(string message, Exception exception)
: base(message, exception)
{
}
}
public class BaseException : Exception
{
public BaseException(string message , Exception exception) : base(message , exception) …Run Code Online (Sandbox Code Playgroud) c# ×2
.net ×1
asp.net-mvc ×1
devforce ×1
json ×1
sharepoint ×1
silverlight ×1
sql-server ×1
tdd ×1
transactions ×1
wpf ×1