所以这是我的一个课程的摘录:
[ThreadStatic]
readonly static private AccountManager _instance = new AccountManager();
private AccountManager()
{
}
static public AccountManager Instance
{
get { return _instance; }
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它是一个单线程每线程 - 即实例标有ThreadStatic属性.该实例也被实例化为静态构造的一部分.
既然如此,当我尝试使用Instance属性时,我的ASP.NET MVC应用程序中是否有可能出现NullReferenceException?
我正在尝试使用SQL Server和Windows身份验证在Vista(IIS7)上运行ASP.NET网站.无论我做什么,当我连接到数据库时,我得到例外:
SqlException was unhandled
Login failed for user 'MyDomain\MachineName$'.
我应用的设置似乎并不重要,我无法让IIS7通过我的Windows登录凭据.
额外细节:
救命!
在ADO.Net实体框架中,我有一个对象,它有4个对其他对象的引用.出于某种原因,当我查询这些引用时,其中两个自动加载(如预期的那样),其中两个总是返回null.
奇怪的是,当我手动询问引用加载时,它们加载的只是花花公子.
举个例子:
if (account.HoldingEntity == null &&
account.HoldingEntityReference.EntityKey != null) {
account.HoldingEntityReference.Load();
account.HoldingEntity = account.HoldingEntityReference.Value;
}
Run Code Online (Sandbox Code Playgroud)
当我第一次检查时HoldingEntity它始终为null,但是Load将返回HoldingEntity而没有问题.
有线索吗?
谢谢!
假设我有一个为学生提供搜索功能的控制器:
public class StudentSearchController
{
[HttpGet]
public ActionResult Search(StudentSearchResultModel model)
{
return View(model);
}
}
Run Code Online (Sandbox Code Playgroud)
只要为搜索操作提供了StudentSearchResultModel,它就会呈现搜索结果列表.
有没有办法从另一个控制器有效地扩展此操作方法?例如,假设我想要其他需要搜索学生的控制器,如下所示:
public class UniStudentController
{
[HttpPost]
public ActionResult Search(UniStudentSearchResultModel model)
{
return RedirectToAction("Search", "StudentSearch", model);
}
}
public class HighSchoolStudentController
{
[HttpPost]
public ActionResult Search(HighSchoolSearchResultModel model)
{
return RedirectToAction("Search", "StudentSearch", model);
}
}
Run Code Online (Sandbox Code Playgroud)
(假设两个模型都扩展了StudentSearchResultModel.)
我显然不能这样做,因为我无法将预先实例化的模型类传递给搜索控制器(原始搜索控制器将重新创建StudentSearchResultModel,而不是使用传递的模型).
到目前为止我提出的最佳解决方案是将SearchView.cshtml移动到"Shared"文件夹中,然后我可以直接从Uni/HighSchool控制器渲染视图(而不是调用"RedirectToAction").这很好用,理论上我根本不需要StudentSearchController.但是,我正在构建遗留代码(在这个人为的示例中,StudentSearchController是遗留的),所以没有进行大量的重构,"共享"文件夹对我来说不是一个选项.
另一个解决方案是将所有与搜索相关的操作放入StudentSearchController中 - 因此它将为UniStudentSearch和HighSchoolStudentSearch获取两个操作.我不喜欢这种方法,因为这意味着StudentSearchController需要知道它的所有预期用法.
有任何想法吗?
PS:不反对重构,但受到截止日期的限制!
这是我正在尝试做的简化示例...让我说我有以下接口:
public interface IPerson
{
int Id { get; set; }
}
public interface IModelPerson : IPerson
{
int BeautyCompetitionsWon { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在实际实现中,存在许多不同类型的人(例如IUglyPerson,等等).这些是实体类型的合同,例如如下:
public class PersonEntity : IPerson
{
public int Id { get; set; }
}
public class ModelPersonEntity : PersonEntity, IModelPerson
{
public int BeautyCompetitionsWon { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
注意:我们可能还有每种合同类型的多个实现 - 例如,IModelPerson也可以通过实现SupermodelEntity.
我们想将我们的实体类型映射到DTO,看起来像这样:
public abstract class PersonDto : IPerson
{
public int Id { …Run Code Online (Sandbox Code Playgroud) 我正在尝试找出运行长时间运行加载操作的最佳位置是使用Durandal.
据我所知,加载数据的一般建议是在ViewModel的activate方法中,这是我通常做的 - 类似于:
viewModel.activate = function () {
var loadPromise = myService.loadData();
return $.when(loadPromise).then(function (loadedData) {
viewModel.data(data);
});
};
Run Code Online (Sandbox Code Playgroud)
我知道如果我不在这里回复承诺,那么绑定通常会出现问题 - 正如这个问题和答案所表明的那样.
但是,在activate方法中执行长时间运行的加载操作会使应用程序在加载操作完成时"冻结".例如,如果我的负载现在是这样的呢?
viewModel.activate = function () {
// All loads return a promise
var firstLoad = myService.loadFirstData();
var secondLoad = myService.loadSecondData();
var thirdLoad = myService.loadThirdDataWhichTakesAges();
return $.when(firstLoad, secondLoad, thirdLoad).then(function (one, two, three) {
viewModel.one(one);
viewModel.two(two);
viewModel.three(three);
});
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,URL会更新以反映正在加载的页面,但页面内容仍然显示上一页(我的意思是"冻结").
理想情况下,如果URL应更改为新页面,并且页面内容也应显示新页面(即使尚未返回该页面的数据),也会很好.然后,当每个加载操作返回时,当数据绑定到视图模型时,应更新页面的相关部分.
是否有推荐的方法在Durandal内部实现这一目标?
我目前的解决方案是启动activate方法中的负载,然后填充viewAttached方法中的数据:
var loadPromise;
viewModel.activate = function () …Run Code Online (Sandbox Code Playgroud) 我正在使用 Material-UI v5 并尝试迁移到 usingstyled而不是,makeStyles因为这似乎是现在的“首选”方法。我知道使用makeStyles仍然有效,但我正在尝试接受新的样式解决方案。
我有一个代表导航链接的列表项列表,我想突出显示当前选定的列表项。这是我使用的方法makeStyles:
interface ListItemLinkProps {
label: string;
to: string;
}
const useStyles = makeStyles<Theme>(theme => ({
selected: {
color: () => theme.palette.primary.main,
},
}));
const ListItemLink = ({ to, label, children }: PropsWithChildren<ListItemLinkProps>) => {
const styles = useStyles();
const match = useRouteMatch(to);
const className = clsx({ [styles.selected]: !!match });
return (
<ListItem button component={Link} to={to} className={className}>
<ListItemIcon>{children}</ListItemIcon>
<ListItemText primary={label} />
</ListItem>
);
};
Run Code Online (Sandbox Code Playgroud)
(请注意,这里我使用clsx来确定selected …
我有一个非常简单的桌子,为人们存储标题("先生","太太"等).这是我正在做的简要版本(在这个例子中使用临时表,但结果是相同的):
create table #titles (
t_id tinyint not null identity(1, 1),
title varchar(20) not null,
constraint pk_titles primary key clustered (t_id),
constraint ux_titles unique nonclustered (title)
)
go
insert #titles values ('Mr')
insert #titles values ('Mrs')
insert #titles values ('Miss')
select * from #titles
drop table #titles
Run Code Online (Sandbox Code Playgroud)
请注意,表的主键是聚类的(显式,为了示例),并且标题列有一个非聚集唯一性约束.
以下是select操作的结果:
t_id title
---- --------------------
3 Miss
1 Mr
2 Mrs
Run Code Online (Sandbox Code Playgroud)
查看执行计划,SQL在群集主键上使用非聚集索引.我猜这解释了为什么结果按此顺序返回,但我不知道为什么它会这样做.
有任何想法吗?更重要的是,任何阻止这种行为的方法?我希望按照插入的顺序返回行.
谢谢!
sql-server clustered-index sql-execution-plan non-clustered-index
我正在尝试动态更新jQuery移动按钮上的文本.该按钮实际上是一个设置为按钮的链接.
根据jQuery移动文档,button("refresh")如果您通过javascript操作按钮,则应该调用.然而,当我这样做时,按钮的风格变得疯狂 - 它缩小到半高,按钮看起来很糟糕.
代码基本如下:
$(function() {
// Buttonize
var $button = $("#myCrapButton");
$button.button();
// Change text on click
$button.click(function() {
$button.text("Awesome Button");
$button.button("refresh");
});
});
Run Code Online (Sandbox Code Playgroud)
更重要的是,调用button("refresh")会导致javascript错误:Cannot call method 'removeClass' of undefined.
我知道我可以通过操纵.ui-btn-text span嵌套在按钮内部来解决这个问题 ; 然而,这似乎是错误的方法,因为它需要明确了解jquery Mobile的内部工作原理.
任何人都可以告诉我如何让刷新调用工作?
使用版本:
谢谢!
可以说我有两个这样的类:
public class LocalResources
{
public Color ForegroundColor { get; set; }
}
public static class OrganisationModule
{
public static LocalResources Resources = new LocalResources
{
ForegroundColor = Color.FromRgb(32, 32, 32)
};
}
Run Code Online (Sandbox Code Playgroud)
在XAML代码中,为什么我不能这样做(假设存在所有正确的xml命名空间)?
<TextBlock Foreground="{x:Static Modules:OrganisationModule.Resources.ForegroundColor}" />
Run Code Online (Sandbox Code Playgroud)
当我编译时,我收到错误: Cannot find the type 'OrganisationModule.ColorManager'. Note that type names are case sensitive.
c# ×5
asp.net-mvc ×2
javascript ×2
sql-server ×2
static ×2
ado.net ×1
asp.net ×1
automapper ×1
durandal ×1
emotion ×1
iis-7 ×1
jss ×1
material-ui ×1
reactjs ×1
readonly ×1
wpf ×1
xaml ×1