我正在使用Entity Framework 4构建一个ASP.Net MVC 3应用程序.当执行下面两段代码时,两个变量(query1和query2)的返回类型都是
System.Data.Objects.ObjectQuery<Asset.Model.Equipment>
Run Code Online (Sandbox Code Playgroud)
Query1使用ObjectContext的直接实例,但是,Query2使用存储库模式,即它在EquipmentService中调用GetEquipment,后者又在Equipment Repository中调用相同的命名方法.Service和Repository中的两个方法都返回
IQueryable<Equipment>
Run Code Online (Sandbox Code Playgroud)
如何,这是我的问题,为什么query2只有在我包含时才会起作用
using System.Linq.Dynamic;
Run Code Online (Sandbox Code Playgroud)
在我的控制器的顶部
using (AssetEntities context = new AssetEntities())
{
var query1 = context.Equipments
.OrderBy("it." + sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
}
var query2 = equipService.GetEquipment()
.OrderBy(sidx + " " + sord)
.Skip(pageIndex * pageSize)
.Take(pageSize);
Run Code Online (Sandbox Code Playgroud)
如果我从我的控制器omitt System.Linq.Dynamic,我在Query2中得到一个错误
.OrderBy(sidx + " " + sord)
Run Code Online (Sandbox Code Playgroud)
哪个州
The type arguments for method 'System.Linq.Queryable.OrderBy<TSource,TKey>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,TKey>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么query1可以工作而不必使用System.Linq.Dynamic,但是query2需要它来执行? …
linq-to-entities jqgrid dynamic-linq entity-framework-4 asp.net-mvc-3
我在我的MVC 4剃刀视图中有以下代码,它应该采用名为modifiedDate的DateTime属性,并打印月份名称,即Jan,Feb等,而不是1,2.
@foreach (var post in Model.NewsList)
{
<li class="entry">
<p class="calendar"><em>@post.modifiedDate.Value.Month.ToString("mmm")</em></p>
</li>
}
Run Code Online (Sandbox Code Playgroud)
任何想法如何做到这一点?
谢谢.
我正在开发一个MVC 5 Web应用程序.在我的一个Razor Views中,我有一个表格可以输出几行数据.在每行数据旁边是一个删除按钮.当用户单击删除按钮时,我想要弹出Bootstrap模式,并要求用户确认删除.
@foreach (var item in Model.Data) {
<tr>
<td>...</td>
<td>@Html.ActionLink("Delete", "Delete", new { id = item.ID }, new { @class = "btn btn-danger btn-xs", data_toggle = "modal", data_target = "#myModal" })</td>
</tr>
}
Run Code Online (Sandbox Code Playgroud)
实际上,当用户单击"删除"按钮时,Modal弹出正常,但我似乎无法获取Actionlink参数中的ID以传递到我的模态中的"确认"按钮,以便它随后将被发送到删除我的控制器中的动作.
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Delete Nomination</h4>
</div>
<div class="modal-body">
Are you sure you wish to delete this nomination?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> …
Run Code Online (Sandbox Code Playgroud) 我正在开发一个ASP.Net MVC 3 Web应用程序,我在从复选框列表中获取值时遇到了一些困难.我已经阅读了有关Stackoverflow的大部分问题,但是,我仍然遇到了一些问题.
我有一个ViewModel
public class ViewModelCheckBox
{
public string Id { get; set; }
public string Name { get; set; }
public bool Checked { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
另一个使用上面的viewmodel的ViewModel
public class ViewModelAssignSubSpeciality
{
public ListItem Item { get; set; }
public IList<ViewModelCheckBox> SpecialityList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中
public ActionResult AssignSubSpeciality(int id)
{
//Get a list of all sub-specialities
var SpecialityList = _listService.GetListItemsByID(3).ToList();
//Get a list of sub-specialities for the the passed in id, this is …
Run Code Online (Sandbox Code Playgroud) 我正在使用Entity Framework 4开发一个ASP.Net MVC 3 Web应用程序.当用户登录我的应用程序时,我想将他们的用户实体(firstName,lastName等)存储在一个会话中,然后可以在整个应用程序中访问.
我知道这可能不是一个好主意,因为当ObjectContext关闭/处置时,User实体被分离,用户细节可能会丢失.
我认为另一种方法可能是,当用户登录时,将userID(主键)分配给会话变量,即:
HttpContext.Current.Session["currentUserID"] = user.userID;
Run Code Online (Sandbox Code Playgroud)
然后在UserService类中创建一个类,如下所示:
public static User CurrentUser
{
get
{
return Data.DBEntities.Users.Where(u => u.userID == HttpContext.Current.Session["currentUserID"]).FirstOrDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
哪个应该基于currentUserID会话变量返回用户实体.这不适合我,但是我遇到了一些错误
Cannot convert lambda expression to type 'string' because it is not a delegate type
Delegate 'System.Func<Asset.Model.User,int,bool>' does not take 1 arguments
Run Code Online (Sandbox Code Playgroud)
这种方法我采取的是正确的,还是有更好的方法?
任何反馈都将非常感激.
我通常可以找出我的应用程序所需的任何SQL查询,但我最近被我需要创建的Cross Tab查询所困扰,并且想知道你是否可以提供帮助?
我有3张桌子
Category(catID, catTitle)
Equipment(equipID, make, model, quantity, catID, siteID)
Site(siteID, title)
Run Code Online (Sandbox Code Playgroud)
我想创建一个Cross Tab查询来显示如下所示的结果集
Category Site1 Site2 Site3 Site4 Site5
PC 2 0 10 3 6
Camera 12 4 2 0 8
Printer 3 2 1 1 2
Run Code Online (Sandbox Code Playgroud)
显示的数字表示每个站点中每个类别项目的总数,使用数量字段和设备表.我以前从未做过Cross Tab查询,而且我正在努力让这个工作.
我正在编写一个带有自定义身份验证和授权的MVC 4 Web应用程序.当用户登录该站点时,我创建了一个FormsAuthenticationTicket并将其存储在cookie中
public void SignIn(string userName, bool createPersistentCookie, string UserData)
{
if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
// Create and tuck away the cookie
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddDays(15), createPersistentCookie, UserData);
// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(authTicket);
//// Create the cookie.
HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
HttpContext.Current.Response.Cookies.Add(faCookie);
}
Run Code Online (Sandbox Code Playgroud)
该的UserData字符串将是一个管道分隔字符串,它总是包含至少两个项目,用户名| UserRole.可以将用户分配给一个或多个角色,因此,UserData可能看起来像此UserID | UserRole | UserRole | UserRole的
然后我在Global.asax中拥有自己的自定义 …
我正在学习如何创建将在我的Web服务器上发送自动电子邮件的Windows服务的教程.我已经有了教程,但是,示例代码每60分钟执行一次服务,相反,我希望每天24小时执行一次服务,比如说每天早上9点.
下面是示例代码
private Timer scheduleTimer = null;
private DateTime lastRun;
private bool flag;
public StarEmailService()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("EmailSource"))
{
System.Diagnostics.EventLog.CreateEventSource("EmailSource", "EmailLog");
}
eventLogEmail.Source = "EmailSource";
eventLogEmail.Log = "EmailLog";
scheduleTimer = new Timer();
scheduleTimer.Interval = 1 * 5 * 60 * 1000;
scheduleTimer.Elapsed += new ElapsedEventHandler(scheduleTimer_Elapsed);
}
protected override void OnStart(string[] args)
{
flag = true;
lastRun = DateTime.Now;
scheduleTimer.Start();
eventLogEmail.WriteEntry("Started");
}
protected void scheduleTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (flag == true)
{
ServiceEmailMethod();
lastRun = DateTime.Now;
flag = …
Run Code Online (Sandbox Code Playgroud) 我有以下代码返回一个对象列表.
var listOfLogins = _logService.GetLogEventsByItemID(137).ToList();
Run Code Online (Sandbox Code Playgroud)
我想获得此列表中的第二个最后一个对象.
有没有人知道如何使用Linq to Entities做到这一点?
谢谢.
我需要从数据库表中清除一些旧数据。下面显示了两个表:app_status和app_personal_details。
我有以下查询来从app_status表中选择从今天起 12 个月内创建的所有记录(应用程序)
select status_id
from dbo.app_status
where submission_date <= dateadd(month, -12, getdate()) order by 1
Run Code Online (Sandbox Code Playgroud)
然后,我想从app_personal_details表中删除上面检索到的 status_id 列表中存在 application_id 的所有记录。
我希望这是有道理的。我想知道从两个表中删除数据的快速方法。
感谢您的帮助。
asp.net-mvc ×3
sql ×2
asp.net ×1
c# ×1
checkbox ×1
checkboxlist ×1
crosstab ×1
datetime ×1
dynamic-linq ×1
entity ×1
jqgrid ×1
linq ×1
razor ×1
sql-server ×1
timer ×1
tostring ×1
viewmodel ×1