我想要做的是为同一列使用多个CASE WHEN条件.
这是我的查询代码:
SELECT Url='',
p.ArtNo,
p.[Description],
p.Specification,
CASE
WHEN 1 = 1 or 1 = 1
THEN 1
ELSE 0
END as Qty,
p.NetPrice,
[Status] = 0
FROM Product p (NOLOCK)
Run Code Online (Sandbox Code Playgroud)
但是,我想要做的是对同一列"qty"使用多个WHEN.
如下面的代码所示:
IF
// CODE
ELSE IF
// CODE
ELSE IF
// CODE
ELSE
// CODE
Run Code Online (Sandbox Code Playgroud) 我使用dapper将数据库中的对象作为IEnumerable返回.默认dapper的缓冲区设置为true.
这是如何运作的?
如果dapper缓存第一个查询,然后从内存中获取对象.
如果有人在表中编辑/删除/添加行会发生什么.必须再次为此查询重新缓存所有数据吗?
我试图从我的控制器返回一个Json结果,并使用jQuery填充选择列表.但代码甚至没有在我的控制器中击中Json方法.
我的选择清单
<select id="MyList"></select>
Run Code Online (Sandbox Code Playgroud)
我的javascript
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("@Url.Action("GetProductJson", "Product")", null, function (data) {
$("#MyList").addItems(data);
});
});
$.fn.addItems = function (data) {
return this.each(function () {
var list = this;
$.each(data, function (index, itemData) {
var option = new Option(itemData.Text, itemData.Value);
list.add(option);
});
});
};
</script>
Run Code Online (Sandbox Code Playgroud)
我在ProductController中的Json方法
[HttpGet]
public JsonResult GetProductJson()
{
var list = new List<SelectListItem>
{
new SelectListItem { Value = "1", Text = "Aron" },
new SelectListItem { Value = "2", Text = "Bob" }, …
Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio 2017.当我在开发asp.net核心MVC时创建新视图时,新文件使用ANSI编码保存.要解决这个问题,我需要在Notepad ++中打开文件,然后使用BOM将编码更改为UTF8.
更新:它只用ANSI创建的asp.net视图,默认情况下所有其他文件如.cs都在utf8中.
我正在使用ASP.NET Webforms项目并使用Unity for DI.该项目还使用DevExpress ASP.NET Ajax控件.
现在我们遇到了问题,似乎是DevExpress和Unity之间的冲突.
这是Unity配置
[assembly: WebActivator.PostApplicationStartMethod(typeof(Sales.Web.App_Start.UnityWebFormsStart), "PostStart")]
namespace Sales.Web.App_Start
{
/// <summary>
/// Startup class for the Unity.WebForms NuGet package.
/// </summary>
internal static class UnityWebFormsStart
{
/// <summary>
/// Initializes the unity container when the application starts up.
/// </summary>
/// <remarks>
/// Do not edit this method. Perform any modifications in the
/// <see cref="RegisterDependencies" /> method.
/// </remarks>
internal static void PostStart()
{
IUnityContainer container = new UnityContainer();
HttpContext.Current.Application.SetContainer(container);
RegisterDependencies(container);
}
/// <summary> …
Run Code Online (Sandbox Code Playgroud) 在我的解决方案中,我有两个项目.
项目1(核心)使用Dapper将SQL映射到DTO
项目2(WebUI - ASP.NET MVC 4)这里我使用每个View的ViewModel.
控制器的示例
[HttpGet]
public ActionResult Edit(int id)
{
// Get my ProductDto in Core
var product = Using<ProductService>().Single(id);
var vm = new ProductFormModel(product);
return View(vm);
}
Run Code Online (Sandbox Code Playgroud)
ViewModel的示例
public class ProductFormModel : BaseViewModel, ICreateProductCommand
{
public int ProductId { get; set; }
public int ProductGroupId { get; set; }
public string ArtNo { get; set; }
public bool IsDefault { get; set; }
public string Description { get; set; }
public string Specification { get; …
Run Code Online (Sandbox Code Playgroud) 我试图用DapperExtensions创建一个通用的Find方法
这是我的方法
public IEnumerable<T> Find(Expression<Func<T, object>> expression)
{
using (IDbConnection cn = GetCn())
{
cn.Open();
var predicate = Predicates.Field<T>(expression, Operator.Eq, true);
return cn.GetList<T>(predicate);
}
}
Run Code Online (Sandbox Code Playgroud)
但我接受System.NullReferenceException
了这一行 var predicate = Predicates.Field<T>(expression, Operator.Eq, true);
这是来自DapperExtensions帮助文档但我尝试将其转换为Generic方法.
using (SqlConnection cn = new SqlConnection(_connectionString))
{
cn.Open();
var predicate = Predicates.Field<Person>(f => f.Active, Operator.Eq, true);
IEnumerable<Person> list = cn.GetList<Person>(predicate);
cn.Close();
}
Run Code Online (Sandbox Code Playgroud) 我试图将动态查询从dapper转换为IDictionary
const string sql = @"SELECT Name, Street FROM Contact";
dynamic query = null;
using (var cn = Connection)
{
query = cn.Query<dynamic>(sql);
}
var rows = query as IDictionary<string, object>;
foreach (var row in rows)
{
// Getting values and objects
}
Run Code Online (Sandbox Code Playgroud)
但是演员总是返回null.任何线索?
我试图将一个事件从一个实例委托给另一个实例。
我在页面顶部有一个工具栏,其中有一个像这样的按钮
<div id="toolbar">
<button v-on:click="add" class="btn btn-default" type="submit"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Ny</button>
</div>
Run Code Online (Sandbox Code Playgroud)
此添加事件在此 vue 实例中工作
var toolbarApp = new Vue({
el: '#toolbar',
data: {
},
methods: {
add: function (event) {
alert('lol');
}
}
});
Run Code Online (Sandbox Code Playgroud)
但现在我想将此添加事件附加到另一个实例,如下所示
var contactApp = new Vue({
mixins: [toolbarApp],
el: '#contact',
data: {
showGrid: true,
showForm: false,
editMode: false
},
created: function () {
this.getContacts();
},
methods: {
getContacts: function () {
$.getJSON(this.apiGrid, function (data) {
this.contacts = data;
}.bind(this));
},
add: function (event) …
Run Code Online (Sandbox Code Playgroud) 我在ASP.NET WebForms解决方案中使用dapper.
我处理数据的所有类都从这个基类中检索一个打开的连接
public abstract class SalesDb : IDisposable
{
protected static IDbConnection OpenConnection()
{
IDbConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["SalesDb"].ConnectionString);
connection.Open();
return connection;
}
public void Dispose()
{
OpenConnection().Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
使用此基类的服务类的示例
public class LeadService : SalesDb
{
public IEnumerable<LeadDto> Select()
{
using (IDbConnection connection = OpenConnection())
{
return connection.Query<LeadDto>("Lead_Select",
null, null, true, null, CommandType.StoredProcedure);
}
}
}
Run Code Online (Sandbox Code Playgroud)
是否有任何缺点:)OpenConnection(
基类中的方法是静态的,并为每个调用返回一个新实例?
c# ×6
dapper ×5
asp.net ×2
asp.net-mvc ×2
.net ×1
architecture ×1
caching ×1
jquery ×1
sql ×1
vue.js ×1