小编Wac*_*urn的帖子

"挑战"一词代表什么?

ControllerBaseclass has Challenge方法,返回ChallengeResult类的对象. CookieAuthenticationOptionsAutomaticChallenge有财产.

我认为ChallengeResult与外部登录有关.但它是如何实际工作的?"挑战"一词来自哪里?这里面有什么.

asp.net-mvc asp.net-identity asp.net-core

18
推荐指数
1
解决办法
4915
查看次数

CHECKSUM_AGG()和CHECKSUM()之间有什么区别?

CHECKSUM_AGG()和CHECKSUM()之间有什么区别?

t-sql

14
推荐指数
2
解决办法
9419
查看次数

插入非空列后触发

我有一个包含两个表not nullCreatedUpdated.

我写了相应的触发器

ALTER TRIGGER [dbo].[tr_category_inserted] ON [dbo].[Category]
AFTER INSERT
AS
BEGIN
  UPDATE Category
  SET Created = GETDATE(), Updated = GETDATE()
  FROM inserted
  WHERE Category.ID = inserted.ID;
END
Run Code Online (Sandbox Code Playgroud)

ALTER TRIGGER [dbo].[tr_category_updated] ON [dbo].[Category]
AFTER UPDATE
AS
BEGIN
  UPDATE Category
  SET Updated = GETDATE()
    FROM inserted
        inner join [dbo].[Category] c on c.ID = inserted.ID
END
Run Code Online (Sandbox Code Playgroud)

但如果我插入一个新行,我会收到一个错误

无法将值NULL插入"创建"列,表"类别"; 列不允许空值.INSERT失败.

插入命令:

INSERT INTO [Category]([Name], [ShowInMenu], [Deleted])
     VALUES ('category1', 0, 0)
Run Code Online (Sandbox Code Playgroud)

如何在没有设置这些列的情况下编写此类触发器以允许null?

sql t-sql sql-server triggers

12
推荐指数
1
解决办法
9917
查看次数

TypeScript接口实现不检查方法参数

interface IConverter {
    convert(value: number): string
}

class Converter implements IConverter {
    convert(): string { // no error?
        return '';
    }
}

const v1: IConverter = new Converter();
const v2: Converter = new Converter();

v1.convert(); // error, convert has parameter, although Converter's convert doesn't expect one
v2.convert(); // ok, convert has no parameters, although Converter implements IConverter which should has paramater
Run Code Online (Sandbox Code Playgroud)

Converterimplements IConverter,它有一个带有一个参数的方法,但Converter缺少这个参数.如果我们不完全实现此接口,为什么TS编译器不会引发错误?

typescript

12
推荐指数
2
解决办法
920
查看次数

实体框架在Web api/MVC中使用异步控制器进行处理

我有这个小代码示例:

public class ValueController : ApiController
{
    private EstateContext _db;

    public ValueController()
    {
        _db = new EstateContext();
    }

    [HttpPost]
    public async void DoStuff(string id)
    {
        var entity = await _db.Estates.FindAsync(id); //now our method goes out and Dispose method is calling
        //returns here after disposing
        _db.SaveChanges(); // _db is disposed

    }

    protected override void Dispose(bool disposing)
    {
        base.Dispose(disposing);
        _db.Dispose();
    }
}
Run Code Online (Sandbox Code Playgroud)

每个ApiController/Controller都实现了IDisposable接口.所以在Dispose方法中我想释放任何资源,比如DbContext.但是如果使用async,则此Dispose方法在第一次出现await时调用.所以在等待之后我已经处理了DbContext.那么在使用异步时处理EF上下文的最佳方法是什么?事实证明,在控制器中不可能依赖Dispose方法?

c# asp.net asp.net-mvc entity-framework asp.net-web-api

10
推荐指数
1
解决办法
3779
查看次数

SqlDataAdapter在Fill()函数后关闭SqlConnection吗?

是否SqlDataAdapter关闭SqlConnectionFill()功能还是需要关闭它自己?

string cnStr = @"Data Source=TEST;Initial Catalog=Suite;Persist Security Info=True;User ID=app;Password=Immmmmm";
cn = new SqlConnection(cnStr);
SqlCommand cmd = new SqlCommand("SELECT TOP 10 * FROM Date", cn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
adapter.Fill(ds);

cn.Close() // ????????

Console.WriteLine(ds.Tables[0].Rows.Count);
Console.WriteLine(cn.State);
Run Code Online (Sandbox Code Playgroud)

.net c# sql-server sqlconnection sqlconnection.close

8
推荐指数
2
解决办法
2万
查看次数

使用错误行号在XSD上验证XML

有没有办法使用错误行号的输出验证XSD架构上的XML文件?

XmlReader阅读器不允许使用行号,它只显示元素名称.

.net c#

7
推荐指数
2
解决办法
7470
查看次数

在POST操作中更改ViewModel属性

我有这个POST动作:

[HttpPost]
public ActionResult GetReport(GetReportModel model)
{
    if (!ModelState.IsValid)
    {
        return View(model);
    }

    return View("GetReport", new GetReportModel()
       { 
          Identifier = "test", 
          Permission = true 
       });
}
Run Code Online (Sandbox Code Playgroud)

当我发布表单时,执行此操作后,生成的视图中没有任何更改.我的意思是,TextBoxfor Identifier没有我在动作中设置的"test"字符串值.但如果我清除ModelState,View将显示新值:

[HttpPost]
public ActionResult GetReport(GetReportModel model)
{
    if (!ModelState.IsValid)
    {
        return View();
    }

    ModelState.Remove("Identifier");
    ModelState.Remove("Permission");

    return View("GetReport", new GetReportModel() 
       {
          Identifier = "test", 
          Permission = true 
       });
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会这样?如果模型状态无效,为什么每个人都将模型返回到View?例如,Microsoft的默认项目模板具有以下代码:

public ActionResult Login(LoginModel model, string returnUrl)
{
    if (ModelState.IsValid)
    {
        return RedirectToLocal(returnUrl);
    }
    // Why do they pass the …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc http-post

3
推荐指数
1
解决办法
1045
查看次数

订购OrderBy,Where,在Linq查询中选择

考虑这个示例代码

System.Collections.ArrayList fruits = new System.Collections.ArrayList();
fruits.Add("mango");
fruits.Add("apple");
fruits.Add("lemon");

IEnumerable<string> query = fruits.Cast<string>()
    .OrderBy(fruit => fruit)
    .Where(fruit => fruit.StartsWith("m"))                
    .Select(fruit => fruit);
Run Code Online (Sandbox Code Playgroud)

我有两个问题:

  1. Select如果自己Where返回相同的类型,是否需要编写最后一个子句?这个例子来自msdn,为什么他们总是写它?
  2. 这些方法的正确顺序是什么?订单会影响某些事情吗?如果我换 SelectWhere,或OrderBy

.net c# linq

3
推荐指数
2
解决办法
1852
查看次数

XmlSerializer奇怪的事情

对不起我的英语不好.我对XmlSerializer很奇怪.这是我的代码

[Serializable]
public class Radio
{
    public bool hasSubWoofers;
    public double[] stationPresets;

    [XmlIgnoreAttribute]
    public string radioId = "X-3454";
}

[Serializable]
public class Car
{
    public Radio radio = new Radio();
    public int speed;
}

[Serializable]
public class JamesBondCar : Car
{
    public bool canFly;
    public bool canSubmerge;

    private string flag = "string flag";
}
Run Code Online (Sandbox Code Playgroud)

class JamesBondCar有私有成员'flag',在序列化期间,XmlSerializer不应该序列化它.在XML中,我正在寻找它.是'标志'字段:

<JamesBondCar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <radio>
    <hasSubWoofers>true</hasSubWoofers>
    <stationPresets>
      <double>192.3</double>
      <double>45.2</double>
      <double>456.3</double>
    </stationPresets>
  </radio>
  <speed>342</speed>
  <canFly>true</canFly>
  <canSubmerge>false</canSubmerge>
</JamesBondCar>
Run Code Online (Sandbox Code Playgroud)

但是,这是主要功能:

            JamesBondCar bond = new JamesBondCar();
            bond.canFly = true; …
Run Code Online (Sandbox Code Playgroud)

.net c#

2
推荐指数
1
解决办法
148
查看次数