我使用Entity Framework 从不同的应用程序调用相同的数据库.但是,当一个应用程序正在读取/更新记录时,我不希望其他应用程序读取该数据.
我尝试使用以下示例代码; 但是,他们仍然能够阅读记录.
任何建议或不同的方法将受到高度赞赏!
using (Entities context = new Entities(ConnectionString))
{
DBTable entity;
do
{
entity = context.DBTable
.Where(item => item.IsLock == false)
.FirstOrDefault();
if (entity != null)
{
// Map entity to class
......
// Lock the record; it will be unlocked later by a calling method.
entity.IsLock = true;
context.SaveChanges();
count++;
}
} while (entity != null && count < 100);
}
Run Code Online (Sandbox Code Playgroud)
编辑:基本上,我读了一个记录并做了一些事情(有时需要很长时间).然后使用成功/失败标志更新记录(如果失败,则可以再次执行此操作).我不希望其他应用程序多次执行成功任务.
.net entity entity-relationship entity-framework entity-framework-4
在过去,我们将控件命名为lblFirstName,txtFirstName.
我看到越来越多的全名,如FirstNameLabel,FirstNameTextBox.显然,它没有任何不同.
我的问题是微软是否正式推荐使用像FirstNameLabel这样的全名.
如果有人问这个问题,请原谅我.
我试图找到通过 UserControl 在Repeater中呈现的TextBoxes的值,即Repeater具有UserControl的占位符,而UserControl内部是TextBox标记实际存在的位置.之前我已经用直接在 Repeater 内部的TextBoxes完成了这个,这是相当直接的,我想知道为什么这显然不能以同样的方式完成.这是带有Repeater的Default页面,其中包含一个Placeholder ...
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<form class="formee">
<fieldset>
<legend>Faculty Information</legend>
<div class="grid-4-12">
<asp:Label ID="lblFirstName1" runat="server" Text="First Name"></asp:Label>
<asp:Label ID="lblFirstName2" runat="server" Text="" ></asp:Label>
<asp:Label ID ="lblSalary" runat="server" Text="" ClientIDMode="Static"></asp:Label>
</div>
<div class="grid-6-12">
<asp:Label ID="lblLastName1" runat="server" Text="Last Name"></asp:Label>
<asp:Label ID="lblLastName2" runat="server" Text=""></asp:Label>
</div>
</fieldset>
</form>
<div id="repeaterDiv">
<asp:Repeater ID="rptBudget" runat="server" ClientIDMode="Static">
<ItemTemplate>
<asp:PlaceHolder ID="phBudget" runat="server" EnableViewState="true" />
<br />
</ItemTemplate>
</asp:Repeater>
<asp:Button ID="btnAddBudgetControl" runat="server" Text="Add"
CausesValidation="false" OnClick="AddBudgetControl" CssClass="addBudgetControl"/>
<asp:Button ID="btnDisplayEntries" runat="server" Text="Display Entries" CausesValidation="false" …Run Code Online (Sandbox Code Playgroud) 我有一个有3列的表.我想转换成单行.

both append.('</tr><tr>') and after.('</tr><tr>') do not work.
Run Code Online (Sandbox Code Playgroud)
想要这样的移动友好页面 -

谢谢您的帮助!
我的应用程序与VS 2013的Web API默认模板完全一样.基本上,Web API 2用于API,MVC 5用于文档.
我正在使用Autofac,到目前为止它运行良好.以下是我所拥有的精简版 -
var builder = new ContainerBuilder();
var assemblies = Assembly.GetExecutingAssembly();
builder.RegisterControllers(assemblies);
builder.RegisterApiControllers(assemblies);
builder.RegisterType<MyService>().As<IMyService>()
.InstancePerHttpRequest();
var apiResolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = apiResolver;
var mvcResolver = new AutofacDependencyResolver(container);
DependencyResolver.SetResolver(mvcResolver);
Run Code Online (Sandbox Code Playgroud)
到目前为止,InstancePerHttpRequest适用于MVC和Web API.
我想知道使用InstancePerHttpRequest而不是InstancePerApiRequest的缺点,所以如果我将来遇到问题,我不会感到惊讶.
我发现了类似的问题,但它没有回答我的问题.
注意:我在SO中找到了一些答案,说我们不应该在同一个项目中混合使用MVC和Web API.对我来说,我只需要很少的MVC网页来获取文档,所以我不想创建新的MVC项目.
提前致谢!
我有一个提交按钮的注册页面.
我希望在"用户点击提交按钮"时显示一个警告框,之后"用户输入的数据将插入数据库中".
int i = obj.IU_SubscriberMaster(0, txtFirstname.Text, txtLastname.Text, txtEmail.Text, txtPassword.Text);
if (i > 0)
{
Call ErrorTrap("errormsg");
}
Run Code Online (Sandbox Code Playgroud)
这是我想要显示警报的地方.我用了
function alerts(str) {
return false;
}
Run Code Online (Sandbox Code Playgroud)
而不是通过创建一个函数errortrap
public void ErrorTrap(string str)
{
if (!ClientScript.IsStartupScriptRegistered("alert"))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用
有人可以帮忙吗?
我有这个问题.我正在建立一个社交网站,我必须在两列中创建帖子.父容器是一个部分,而"post"元素是其样式为float:left的文章.如何让我们滑到那些在较短的空间下创建的空白空间的位置?

我是ASP.Net的新手,一般都有关于ValidationSummary或Validator的简单问题.问题是,即使没有验证错误,我的警报div仍然显示.ASP.Net生成用于客户端验证的代码,因此我如何仅在发生错误时显示警报div,这是否可能?我认为ValidationSummary可能在这种情况下有所帮助,但我不确定,希望有人可以帮助我.
当前页面:
<asp:Login ID="LoginForm" runat="server" ViewStateMode="Disabled" RenderOuterTable="False" OnAuthenticate="LoginForm_Authenticate">
<LayoutTemplate>
<div class="alert alert-danger" role="alert">
<p><asp:RequiredFieldValidator ID="RequiredFieldValidatorUserName" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="UserName" Display="Dynamic"></asp:RequiredFieldValidator></p>
<p><asp:RequiredFieldValidator ID="RequiredFieldValidatorPassword" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="Password" Display="Dynamic"></asp:RequiredFieldValidator></p>
</div>
<div class="form-group">
<asp:TextBox runat="server" CssClass="form-control" ID="UserName" />
<asp:TextBox runat="server" CssClass="form-control" ID="Password" TextMode="Password"/>
</div>
<asp:Button runat="server" ID="Login" CommandName="Login" CssClass="btn btn-default btn-primary" Text="Login" />
</LayoutTemplate>
</asp:Login>
Run Code Online (Sandbox Code Playgroud) Model:
public class SelectBillingSiteReportModel
{
public IEnumerable<SelectListItem> Sites { get; set; }
public string SelectedSiteName { get; set; }
public string SelectedSiteKey { get; set; }
[Required]
[DataType(DataType.Date)]
public DateTime FromDateTime { get; set; }
[Required]
[DataType(DataType.Date)]
public DateTime ToDateTime { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
View:
@model MuseReport.Models.SelectBillingSiteReportModel
@{
ViewBag.Title = "Select Site and Date Range";
}
<div class="page-header">
<h4>Select Site and Date Range for Ecg Billing Summary</h4>
</div>
<div class="row">
@using (Html.BeginForm("EcgBilling", "BillingRpt"))
{
<div class ="form-horizontal" role="form">
<div …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用从另一个控制器调用方法RedirectToAction()。但这是行不通的。您能解释一下我在做什么错吗?
[HttpPost]
public ActionResult AddToWishList(int id, bool check)
{
var currentUser = WebSecurity.CurrentUserId;
if (currentUser != -1)
{
// ...
}
else
{
return RedirectToAction("Login", "Account");
}
}
Run Code Online (Sandbox Code Playgroud)
我在HTML中调用该方法:
<script>
$(document).ready(function () {
/* call the method in case the user selects a checkbox */
$("#checkbox".concat(@Model.Id)).change(function () {
$.ajax({
url: '@Url.Action("AddToWishList", "Item")',
type: 'POST',
data: {
id: '@Model.Id',
check: this.checked
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
如果我使用它会起作用:
success: function (result) {
window.location.href = "@Url.Content("~/Account/Login")";
}
Run Code Online (Sandbox Code Playgroud)
但是,只有在未授权用户的情况下,我不需要在每次单击后导航到Login()。您能否解释一下如何在控制器中使用重定向?