以下有何不同之处
CreateQuery() ExecuteFunction(), ExecuteStoreQuery() and ExecuteStoreCommand()
Run Code Online (Sandbox Code Playgroud)
据我所知,CreateQuery用于Entity SQL,其余的方法用于在DB中定义的sql函数或存储过程.
根据ObjectContext类元数据,它们如下:
CreateQuery():Creates an System.Data.Objects.ObjectQuery<T> in the current object context by using the specified query string.
Returned -> System.Data.Objects.ObjectQuery<T>
ExecuteFunction(): Executes a stored procedure or function that is defined in the data source and expressed in the conceptual model; discards any results returned from
the function; and returns the number of rows affected by the execution.
Returned -> The number of rows affected.
This has an overloaded version which return -> The entity …Run Code Online (Sandbox Code Playgroud) 我有两个申请
计划身份验证如下
现在,在关闭应用程序的服务器端,我需要确认每个请求的令牌都没有被篡改.
到目前为止,我已经编写了下面的代码来创建一个POC.
========================= OWIN配置========
[assembly: OwinStartup(typeof(WebApi.App_Start.Startup))]
namespace WebApi.App_Start
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
ConfigureOAuth(app);
WebApiConfig.Register(config);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
app.UseWebApi(config);
}
public void ConfigureOAuth(IAppBuilder app)
{
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = false,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider(),
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new
OAuthBearerAuthenticationOptions());
}
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个基类和一个派生类,如下所示
public class animal
{
public string name { get; set; }
}
public class dog : animal
{
public int age { get; set; }
public string type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
animal a = new animal();
dog d = new dog();
a = d; //compiled
d = a; //Error:Cannot implicitly convert type 'animal' to 'dog'.
d = (dog)a; // compiled
Run Code Online (Sandbox Code Playgroud)
内部派生类可以分配给base但是需要进行反向显式转换?即使base和derived类都包含相同的成员,也会发现相同的结果.
我们正在整个应用程序中使用Ajax调用 - 尝试在尝试执行任何Ajax请求时,如果会话已经过期,则尝试找到重定向到登录页面的全局解决方案.我编写了以下解决方案,从这篇文章中获取帮助 - 在ajax调用中处理会话超时
不确定为什么在我关心的事件中"HandleUnauthorizedRequest"没有被解雇.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class CheckSessionExpireAttribute :AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
var url = new UrlHelper(filterContext.RequestContext);
var loginUrl = url.Content("/Default.aspx");
filterContext.HttpContext.Session.RemoveAll();
filterContext.HttpContext.Response.StatusCode = 403;
filterContext.HttpContext.Response.Redirect(loginUrl, false);
filterContext.Result = new EmptyResult();
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器操作中使用Above自定义属性如下:
[NoCache]
[CheckSessionExpire]
public ActionResult GetSomething()
{
}
Run Code Online (Sandbox Code Playgroud)
AJAX Call(JS部分):
function GetSomething()
{
$.ajax({
cache: false,
type: "GET",
async: true,
url: "/Customer/GetSomething",
success: function (data) {
},
error: function (xhr, …Run Code Online (Sandbox Code Playgroud) 数据库:Postgresql
ORM:带有 Npgsql.EntityFrameworkCore.PostgreSQL 的实体框架核心
尝试调用以下函数将产品列表作为 json 传递
dbContext.product.FromSqlRaw("SELECT pa.usp_set_product({0})", productjson).ToList();
Run Code Online (Sandbox Code Playgroud)
返回错误为:“42883:函数 pa.usp_set_product(text) 不存在”
然后尝试下面
dbContext.product.FromSqlRaw(@"SELECT pa.usp_set_product('" + productjson+ "')").ToList();
Run Code Online (Sandbox Code Playgroud)
返回错误:“输入字符串的格式不正确”
然后尝试下面效果很好
using (var cmd = new NpgsqlCommand(@"SELECT pa.usp_set_product(@productjson)", conn))
{
cmd.Parameters.Add(new NpgsqlParameter("productjson", NpgsqlDbType.Json) { Value = productjson});
cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
任何想法,请-
谢谢,
@保罗
c# ×4
ajax-request ×1
asp.net-mvc ×1
base ×1
derived ×1
difference ×1
docker ×1
npgsql ×1
owin ×1
types ×1