对不起我的英语不好.
我正在使用Entity Framework 4.0(模型优先)编写我的项目.在项目开始时,我遇到了这个问题:我试图在数据库中插入填充的对象,但我得到一个例外:
"无法将值NULL插入列'CategoryId',表'ForumDB.dbo.Categories';列不允许空值.INSERT失败.语句已被终止."
Category usingCategory = new Category("Using Forums", "usingforums", 0);
using (Context)
{
Context.Categories.AddObject(usingCategory);
Context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
我检查了这个对象,我确信它已经填满了.
以防万一:
public Category(string name, string urlName, int index)
{
CategoryId = Guid.NewGuid();
Name = name;
UrlName = urlName;
CategoryIndex = index;
}
Run Code Online (Sandbox Code Playgroud)
请告诉我发生了什么事?谢谢你的帮助!
简化Startup
代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "",
defaults: new { controller = "Main", action = "Index" });
});
}
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2015中运行应用程序后,我在浏览器中看到"localhost:xxx",但是我没有看到MainController.Index()的结果.只是空白页面.我错过了什么?
更新:
Web.config文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
更新2:
问题来自依赖注入服务到控制器的异常,因为我忘记使用开发人员异常页面站点只是向我返回空白页面.所以我很抱歉不正确的问题,但在我的情况下,路由很好.
可能重复:
侦听依赖项属性的更改
对不起我的英语.
我需要创建一个可以订阅更改DependencyProperty的类,并根据此属性的新值来执行某些操作.
像这样:
MyClass obj = new MyClass();
obj.Subscribe(TextBox.TextProperty, myTextBox);
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我从第三方静态页面(由Adobe Muse生成)捕获发布请求并使用MVC操作处理它.
<form method="post" enctype="multipart/form-data">
<input type="text" name="Name">
...
</form>
Run Code Online (Sandbox Code Playgroud)
路由空表单操作:
app.UseMvc(routes => routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}"));
Run Code Online (Sandbox Code Playgroud)
但是根据行动我有模型,每个属性都是空的
行动:
[HttpPost]
public void Index(EmailModel email)
{
Debug.WriteLine("Sending email");
}
Run Code Online (Sandbox Code Playgroud)
模型:
public class EmailModel
{
public string Name { get; set; }
public string Email { get; set; }
public string Company { get; set; }
public string Phone { get; set; }
public string Additional { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Request.Form
从表单中获取所有值,但模型为空
[0] {[Name, Example]}
[1] {[Email, Example@example.com]}
[2] {[Company, …
Run Code Online (Sandbox Code Playgroud) 点击很难重现我有一个错误.1-2/10000次点击结束OpenQA.Selenium.WebDriverTimeoutException
.看起来元素没有被点击,驱动程序等待一些反应.
Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -0.028
(Session info: chrome=52.0.2743.116)
(Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 6.3.9600 x86_64)
Stack trace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.InternalExecute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Click()
Run Code Online (Sandbox Code Playgroud)
有时异常消息中的超时看起来是合法的(300秒),但在大多数情况下它具有负值,如-0.028.
我用:
Chrome 52.0.2743.116
Selenium 2.53.1
ChromeDriver 2.23 (also produces with 2.22)
Run Code Online (Sandbox Code Playgroud)
更新:
我也开始得到这个错误 RemoteNavigator.GoToUrl
Type: OpenQA.Selenium.WebDriverTimeoutException
Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from …
Run Code Online (Sandbox Code Playgroud) 我正在编写项目并使用NHibernate 3.1
SimpleTest的:
Forum forum = Session.CreateCriteria<Forum>().Add(Restrictions.Eq("UrlName", "reportabug")).UniqueResult<Forum>();
forum.TopicsCount++;
IForumRepository forumRepository = new ForumRepository(SessionFactory);
forumRepository.Update(forum);
public virtual void Update(TEntity entity)
{
if (!session.Transaction.IsActive)
{
TResult result;
using (var tx = session.BeginTransaction())
{
session.SaveOrUpdate(entity)
tx.Commit();
}
return result;
}
session.SaveOrUpdate(entity)
}
Run Code Online (Sandbox Code Playgroud)
最后一次更新抛出异常:
StaleObjectStateException was unhandled by user code:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)
Run Code Online (Sandbox Code Playgroud)
SQL查询:
UPDATE Forums
SET Name = 'Forums Issues (not product support)' /* @p0 */,
UrlName = 'reportabug' /* @p1 */, …
Run Code Online (Sandbox Code Playgroud) 有没有什么方法可以同时在Asp.net核心和Xamarin上引用某种类型的类库?我想在Web API和手机应用程序中使用一些核心代码.PS.看起来PCL对我不起作用.
我遇到静态属性Calendar的问题.
type
TDateTime = class(TObject)
private
class var fcalendar: TCalendar;
class procedure SetCalendar(const Value: TCalendar);
public
class property Calendar: TCalendar read fcalendar write SetCalendar;
end;
implementation
class procedure TDateTime.SetCalendar(const Value: TCalendar);
begin
if Value <> nil then
begin
TDateTime.fcalendar := Value;
end;
end;
Run Code Online (Sandbox Code Playgroud)
错误发生在第7行
E2355类属性访问器必须是类字段或类静态方法
我在TDateTime中遇到类运算符问题.
type
TDateTime = class(TObject)
public
class operator Add(a: TDateTime; b: TTimeSpan): TDateTime;
class operator Subtract(a: TDateTime; b: TTimeSpan): TDateTime;
end;
implementation
class operator TDateTime.Add(a: TDateTime; b: TTimeSpan): TDateTime;
begin
result := TDateTime.Create(a.Ticks + b.Ticks);
end;
class operator TDateTime.Subtract(a: TDateTime; b: TTimeSpan): TDateTime;
begin
result := TDateTime.Create(a.Ticks - b.Ticks);
end;
Run Code Online (Sandbox Code Playgroud)
错误发生在第4行
E2123预期的程序,功能,财产或VAR
我为Windows写这个.但如果它只适用于.net和iOS,我该如何为Windows做到这一点?
所以我从 Fiddler 那里得到了一些警告,我在 HTTP Location 标头中有错误的 url,它们应该是完全合格的。为什么它如此重要以及会导致哪些问题?
有没有办法获得未绑定泛型类型的参数数量?例如:
f(typeof(List<>)) => 1
f(typeof(Dictionary<,>)) => 2
Run Code Online (Sandbox Code Playgroud)
UPD
我知道从Type.Name获取数字,但也许有一种方法可以直接从Type获取