我想知道如何为生产数据库运行'Update-Database'命令.
"更新 - 数据库"数据库在我的本地计算机上运行良好,但如何使其适用于生产数据?
因此,如果我对我的应用程序进行更改,然后通过visual studio运行"发布",这对于代码方面的工作正常,但是如何为生产数据运行"Update-Database"命令.
希望这个问题有道理......
谢谢,
我一直在使用Dapper和我目前的项目,我将不得不使用ADO.NET.我的问题是如何使用ADO.NET返回IEnumerable?这是我使用Dapper的原因.有人可以帮我转换这个但是用ADO做同样的事吗?
public IEnumerable<Favorites> GetFavorites()
{
using (SqlConnection sqlConnection = new SqlConnection(connString))
{
sqlConnection.Open();
var work = sqlConnection.Query<Favorites>("Select * from favorites");
return work;
}
}
Run Code Online (Sandbox Code Playgroud) 我正试着带上我的菜单.
在我的_Layout.cshtml页面中
<div class="wrapper">
<!-- Navigation -->
@Html.RenderAction("Navigation", "Nav")
Run Code Online (Sandbox Code Playgroud)
导航控制器看起来像这样
public ActionResult Navigation()
{
var pages = pageRepository.Pages;
return View(pages);
}
Run Code Online (Sandbox Code Playgroud)
导航视图看起来像这样
@model IEnumerable<Site.Domain.Entities.Page>
@{
Layout = null;
List<Site.Domain.Entities.Page> pages = new List<Site.Domain.Entities.Page>();
foreach(var page in Model)
{
pages.Add(page);
}
}
@foreach (var link in Model)
{
if (link.ParentPage == "Home")
{
<li>@link.PageTitle</li>
<ul>
@foreach (var subLink in pages)
{
if (subLink.ParentPage == link.PageTitle)
{
<li>@subLink.PageTitle</li>
}
}
</ul>
}
}
Run Code Online (Sandbox Code Playgroud)
当我去.../nav/navigation时,视图工作正常
我想要做的是将它带入我的_Layout页面,以便我可以将它用作我的菜单.
我继续使用@ Html.RenderAction("导航","导航")出错
错误说"'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'的最佳重载方法匹配'有一些无效的参数"
我应该使用它作为部分吗?最好的方法是什么?谢谢你的建议!
这两个人似乎正在做同样的事情。我给它们计时了——知道这只是一个小例子——但它们似乎也以完全相同的速度运行。使用其中一种比另一种有好处吗?
List<string> alpha = new List<string>(new string[] { "a", "b", "c" });
foreach (var letter in alpha)
{
Console.WriteLine(letter);
}
IEnumerable<string> _alpha = new[] {"a", "b", "c"};
foreach(var _letter in _alpha)
{
Console.WriteLine(_letter);
}
Run Code Online (Sandbox Code Playgroud) 我尝试将文件保存到站点中的文件夹中,但不断收到 UnauthorizedAccessException 错误。
[HttpPost]
public ActionResult Edit(Product product, HttpPostedFileBase image)
{
var img = Path.GetFileName(image.FileName);
if (ModelState.IsValid)
{
if (image != null && image.ContentLength > 0)
{
var path = Path.Combine(Server.MapPath("~/Content/productImages/"),
System.IO.Path.GetFileName(image.FileName));
image.SaveAs(path);
product.ImageName = img;
}
// save the product
repository.SaveProduct(product);
// add a message to the viewbag
TempData["message"] = string.Format("{0} has been saved", product.Name);
// return the user to the list
return RedirectToAction("Index");
}
else
{
// there is something wrong with the data values
return View(product);
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 dapper 从表中查询数据,然后将其转换为对象。当它被投射到对象时,guid 属性设置为全零,但所有其他道具设置正确。
public class UserStuff
{
public int Id { get; set; }
public Guid UId { get; set; }
}
public async Task<UserStuff> GetUserStuff(Guid uId){
using(IDbConnection conn = Connection){
string sQuery = "SELECT TOP 100 id, u_id " +
"FROM TestTable WHERE u_id = @u_id ";
conn.Open();
var result = await conn.QueryAsync<UserStuff>(sQuery, new { u_id = uId });
return result.FirstOrDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
示例 SQL 数据:
身份证 | u_id
5 | C9DB345B-D460-4D71-87E0-D9A3B5CE1177
它返回:id 为 5,guid 全为零
我正在尝试检查字符串是否包含两个以上的重复字符.
例如
'aabcd123' = ok
'aaabcd123' = not ok
'aabbab11!@' = ok
'aabbbac123!' = not ok
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的事,但没有运气
if (string.Distinct().Count() > 2){
//do something
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我正在阅读 Pro Asp.net mvc3 框架书。我想更改默认路由,以便我可以拥有不同的主页。我添加了一个名为 Pages 的新控制器和一个名为 Home 的视图。这就是我想要的主页。
我试过将此添加到我的 global.asax.cs
routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
new { controller = "Pages", action = "Home", id = "DefautId" });
Run Code Online (Sandbox Code Playgroud)
这会更改默认页面,但会破坏类别
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(null,
"", // Only matches the empty URL (i.e. /)
new
{
controller = "Product",
action = "List",
category = (string) null,
page = 1
}
);
routes.MapRoute(null,
"Page{page}", // Matches /Page2, /Page123, but not /PageXYZ
new {controller = "Product", action = "List", category = (string) null}, …Run Code Online (Sandbox Code Playgroud) 我只是好奇为什么我必须使用string[]何时使用Directory.GetDirectories()
string[] directories = Directory.GetDirectories("c:\\");
foreach (var dir in directories)
{
Console.WriteLine(dir);
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能用
List<string> _directories = new List<string>();
_directories = Directory.GetDirectories("c:\\");
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用db中的值填充此IEnumerable.
我看不出我做错了什么.
IEnumerable<Categories> categories = new List<Categories>();
List<SelectListItem> catItems = new List<SelectListItem>();
foreach (var cats in categories)
{
catItems.Add(new SelectListItem
{
Text = cats.CategoryName,
Value = cats.CategoryID.ToString()
});
}
Run Code Online (Sandbox Code Playgroud)
这是班级:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace SportsStore.Domain.Entities
{
public class Categories
{
[Key]
public int CategoryID { get; set; }
public string CategoryName { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud) 我有一种情况,我需要在整个过程中建立一个消息.在此过程中,有几个函数和类,此消息必须收集信息.构建此消息的最佳方法是什么?
例:
public class process{
public StringBuilder message = new StringBuilder();
private void DoStep1
{
AddNote("start");
var p2 = new process2();
p2.DoStuff();
var p3 = new process3();
p3.DoStuff();
SendEmailMethod(message);
}
private void AddNote(string msg)
{
//do stuff
message.Append(msg);
}
}
public class process2{
public void DoStuff()
{
//need to append msg to that variable
}
}
public class process3{
public void DoStuff()
{
//need to append msg to that variable
}
}
Run Code Online (Sandbox Code Playgroud) 在复杂where子句中使用 String.StartsWith() 时如何处理空值?
var value = _context.Repo.Pages.Where(r => r.Sdate <= data.Pdate && (r.Edata == null || data.RData <= r.Edata)
&& ......
&& ...... several conditions
&& ......
|| (data.SisPlan.StartsWith("T") && r.SisN == data.SisCal));
Run Code Online (Sandbox Code Playgroud)
我试过了,data?.SisPlan.StartsWith("T")但收到消息:
运算符“&&”不能应用于“bool?”类型的操作数 和“布尔”
我试图防止在where子句之外进行空检查。
我收到错误:
Operator '??' cannot be applied to operands of type 'float' and 'float'
我想要一套'var result' ,如果在float列表中的属性不为空或空。如果它为空,则使用 的默认float值0.0f。
我收到错误的代码是这样的:
var result = calculationsList.Where(x => x.SomeValue == 123).FirstOrDefault().Value ?? 0.0f;
Run Code Online (Sandbox Code Playgroud)
我也试过:
var tVal = calculationsList.Where(x => x.SomeValue == 123).FirstOrDefault().Value;
var result = tVal != null ? tVal : 0.0f;
Run Code Online (Sandbox Code Playgroud) c# ×13
asp.net-mvc ×5
asp.net ×2
dapper ×2
.net ×1
ado.net ×1
duplicates ×1
file-upload ×1
renderaction ×1
string ×1