在SQL Server中经常使用位来表示true和false,但是您不能逐字地为它们分配true和false,它必须是1或0.
我最近偶然发现了以下代码:
CREATE PROCEDURE TestProcedure
@parameter bit = false
AS
BEGIN
...
END
Run Code Online (Sandbox Code Playgroud)
为什么有效?特别是当在存储过程的主体中将位设置为false时不是.
如果使用select查询参数,则确实将其设置为0,表示false.
我正在研究基本的MVC5/EF6应用程序,当我尝试在MVC中构建一个Read Action时遇到以下错误:
Error
There was an error running the selected code generator:
'No Parameterless constructor defined for this object'
Run Code Online (Sandbox Code Playgroud)
它不应该需要它,因为我调用的是读取而不是删除或更新,但是有问题的模型确实有一个无参数构造函数(就像下面的模型一样).
public class Article
{
public int ArticleID { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime PublishDate { get; set; }
public virtual Author Author { get; set; }
public Article()
{
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器在下面,它还有一个无参数构造函数:
public ArticleController()
{
connection = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
context = new TRNContext(connection);
}
// GET: Article …Run Code Online (Sandbox Code Playgroud) 我已经定制了ApplicationDBContext类来通过其构造函数接收连接字符串.它可以在直接调用时连接到数据库OK但是当通过app.CreatePerOwnContext调用时我无法调用它.我的课程定义如下:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(string databaseConnection)
: base(databaseConnection, throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create(string databaseConnection)
{
return new ApplicationDbContext(databaseConnection);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是由以下行中的Startup.Auth.cs调用它.
app.CreatePerOwinContext(ApplicationDbContext.Create);
Run Code Online (Sandbox Code Playgroud)
create方法也采用连接字符串,但以下方法不起作用
app.CreatePerOwinContext(ApplicationDbContext.Create(connectionString));
Run Code Online (Sandbox Code Playgroud)
它会产生以下错误:
Error 1 The type arguments for method 'Owin.AppBuilderExtensions.CreatePerOwinContext<T>(Owin.IAppBuilder, System.Func<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Run Code Online (Sandbox Code Playgroud)
将连接字符串发送到ApplicationDbContext类的正确语法是什么,以便Owin上下文可以引用它?
连接字符串是正确的,但为了完整性,设置它的代码如下.
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
Run Code Online (Sandbox Code Playgroud)