我正在运行EF 4.2 CF并想在我的POCO对象的某些列上创建索引.
举个例子,假设我们有这个员工类:
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeCode { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime HireDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我们经常通过EmployeeCode对员工进行搜索,因为有很多员工,因为性能原因而将索引编入索引会很不错.
我们能用流利的api以某种方式做到这一点吗?或者数据注释?
我知道可以执行这样的sql命令:
context.Database.ExecuteSqlCommand("CREATE INDEX IX_NAME ON ...");
Run Code Online (Sandbox Code Playgroud)
我非常想避免那样的原始SQL.
我知道这不存在,但寻找沿着这些方向的东西:
class EmployeeConfiguration : EntityTypeConfiguration<Employee>
{
internal EmployeeConfiguration()
{
this.HasIndex(e => e.EmployeeCode)
.HasIndex(e => e.FirstName)
.HasIndex(e => e.LastName);
}
}
Run Code Online (Sandbox Code Playgroud)
或者使用System.ComponentModel.DataAnnotations
POCO可能看起来像这样(我知道这不存在):
public class Employee
{ …
Run Code Online (Sandbox Code Playgroud) c# fluent-interface entity-framework-4 data-annotations ef-code-first
我怎样才能告诉我的控制器/模型解析日期时应该具备哪种文化?
我正在使用这篇文章的一些内容将jquery datepicker实现到我的mvc应用程序中.
当我提交日期时,它"在翻译中丢失"我没有使用美国格式的日期,所以当它被发送到我的控制器时它只是变为空.
我有一个用户选择日期的表单:
@using (Html.BeginForm("List", "Meter", FormMethod.Get))
{
@Html.LabelFor(m => m.StartDate, "From:")
<div>@Html.EditorFor(m => m.StartDate)</div>
@Html.LabelFor(m => m.EndDate, "To:")
<div>@Html.EditorFor(m => m.EndDate)</div>
}
Run Code Online (Sandbox Code Playgroud)
我为此创建了一个编辑模板,以实现jquery datepicker:
@model DateTime
@Html.TextBox("", Model.ToString("dd-MM-yyyy"), new { @class = "date" })
Run Code Online (Sandbox Code Playgroud)
然后我创建像这样的datepicker小部件.
$(document).ready(function () {
$('.date').datepicker({ dateFormat: "dd-mm-yy" });
});
Run Code Online (Sandbox Code Playgroud)
这一切都很好.
这是问题的起点,这是我的控制器:
[HttpGet]
public ActionResult List(DateTime? startDate = null, DateTime? endDate = null)
{
//This is where startDate and endDate becomes null if the dates dont have the expected formatting.
}
Run Code Online (Sandbox Code Playgroud)
这就是为什么我想以某种方式告诉我的控制器应该期待什么样的文化?我的模特错了吗?我可以以某种方式告诉它使用哪种文化,比如数据注释属性? …
validation data-annotations jquery-ui-datepicker asp.net-mvc-3
我目前正在使用EF Code First 4.3并启用了迁移,但禁用了自动迁移.
我的问题很简单,是否存在与模型配置等效的数据注释.WillCascadeOnDelete(false)
我想装饰我的类,以便外键关系不会触发级联删除.
代码示例:
public class Container
{
public int ContainerID { get; set; }
public string Name { get; set; }
public virtual ICollection<Output> Outputs { get; set; }
}
public class Output
{
public int ContainerID { get; set; }
public virtual Container Container { get; set; }
public int OutputTypeID { get; set; }
public virtual OutputType OutputType { get; set; }
public int Quantity { get; set; }
}
public class OutputType
{ …
Run Code Online (Sandbox Code Playgroud)