我试图在一个看起来像这样的方法中查询:
Public Shared Function listParticipationsByTeamCount(ByVal count As Integer, ByVal challenge As Challenge) As List(Of Participation)
Dim participationList As List(Of Participation)
If count <> Nothing And challenge IsNot Nothing Then
Using db As New DatabaseEntities()
participationList = db.Participations.Where(Function(x) x.TeamCount = count And x.Challenge.Id = challenge.Id).OrderByDescending(Function(x) x.TeamCount).ThenBy(Function(x) x.Team.Name).ToList()
End Using
End If
Return participationList
End Function
Run Code Online (Sandbox Code Playgroud)
我有一个Participation表,它在Participation和Team表之间有多对一的关系,并且Participation和TeamMember表之间有多对多的关系.在我的标记页面上,当我迭代遍历列表时,我会尝试这样的事情:
<% For Each participation As Participation In participationsList%>
<tr>
<td><a class="external-link" href="<%= participation.Team.Website %>"><%= participation.Team.Name%></a></td> …Run Code Online (Sandbox Code Playgroud) .net entity-relationship entity-framework entity-framework-4
我有一个entityDao,由我的objectDaos的每个人继承.我正在使用Dynamic Linq并尝试使用一些通用查询.
我的EntityDao中的泛型方法中有以下代码:
public abstract class EntityDao<ImplementationType> where ImplementationType : Entity
{
public ImplementationType getOneByValueOfProperty(string getProperty, object getValue){
ImplementationType entity = null;
if (getProperty != null && getValue != null)
{
LCFDataContext lcfdatacontext = new LCFDataContext();
//Generic LINQ Query Here
entity = lcfdatacontext.GetTable<ImplementationType>().Where(getProperty + " =@0", getValue).FirstOrDefault();
//.Where(getProperty & "==" & CStr(getValue))
}
//lcfdatacontext.SubmitChanges()
//lcfdatacontext.Dispose()
return entity;
}
Run Code Online (Sandbox Code Playgroud)
然后我在单元测试中执行以下方法调用(我的所有objectDaos都继承entityDao):
[Test]
public void getOneByValueOfProperty()
{
Accomplishment result = accomplishmentDao.getOneByValueOfProperty
("AccomplishmentType.Name", "Publication");
Assert.IsNotNull(result);
}
Run Code Online (Sandbox Code Playgroud)
以上过程(AccomplishmentType与成就有关系)
Accomplishment result = …Run Code Online (Sandbox Code Playgroud) 我已经看过类似的问题,但它们并不是我所指的(或者它们是,我不明白答案)
在我之前使用Linq2SQL的应用程序中,我能够通过这样做来重载带有参数的构造函数:
Namespace CoreDb
Partial Public Class Accomplishment
Public Sub New(ByVal accomplishmentTypeID As Object, ByVal description As String, ByVal title As String, ByVal applicableDate As DateTime, ByVal lastUpdatedBy As String)
Me.New()
If TypeOf (accomplishmentTypeID) Is Guid Then
Me.AccomplishmentTypeId = accomplishmentTypeID
End If
If TypeOf (accomplishmentTypeID) Is String Then
Me.AccomplishmentTypeId = New Guid(accomplishmentTypeID.ToString())
End If
Me.Description = description
Me.ApplicableDate = applicableDate
Me.Title = title
Me.Id = Guid.NewGuid()
Me.DateCreated = DateTime.Now
Me.DateModified = DateTime.Now
Me.LastUpdatedBy = lastUpdatedBy
Me.CreatedBy = lastUpdatedBy
End Sub …Run Code Online (Sandbox Code Playgroud) 如果我有 User具有以下属性类:
public Guid UserPreferenceId { get; set; }
public virtual DefaultUserPreference UserPreference { get; set; }
public Guid SecondaryUserPreferenceId { get; set; }
public virtual DefaultUserPreference SecondaryUserPreference { get; set; }
Run Code Online (Sandbox Code Playgroud)
如何通过流畅的API获取此信息?当我尝试运行它时,它说:
在表'Users'上引入FOREIGN KEY约束可能会导致循环或多个级联路径.指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束.无法创建约束.查看以前的错误.
我已经看过其中一些问题,但它们总是涉及一个导航属性和一个集合.这种关系也是单向的,但如果必须是双向的,可能是双向的,不确定是否重要.
我无法获得这个LINQ在哪里返回任何结果,我有几个这样的类:
public class RestaurantMenu
{
public List<MenuItem> MenuItems { get; set; }
}
public class MenuItem
{
public decimal Price { get; set; }
public List<FoodItem> FoodItems { get; set; }
}
public class FoodItem
{
public string Label { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
给定一个列表RestaurantMenu,我试图返回任何匹配的结果,其中餐厅菜单的菜单项的食品项目的标签匹配列表中的所有字符串.基本上,你输入你想要吃的食物,它应该返回任何你想要吃的东西的餐馆.它应该支持多个字符串,但我甚至无法匹配一个字符串.
假设如下:
List<RestaurantMenu> allRestaurantMenus = /blah;
List<string> labelOfFoodsDesired = /blah;
Run Code Online (Sandbox Code Playgroud)
我尝试通过链接表达式来实现它:
IQueryable<RestaurantMenu> query = allRestaurantMenus.AsQueryable();
foreach (string foodItem in labelOfFoodItemsDesired)
{
query = query.Where(x => x.MenuItems.Any(y => y.FoodItems.Select(z => z.Label).Contains(foodItem)));
}
List<RestaurantMenu> matchingRestaurantMenus = …Run Code Online (Sandbox Code Playgroud) 我的链接上有CSS,取决于它的链接类型.在这种情况下,它受密码保护,外部链接.
所以我有这样的CSS:
a.external-link:after { padding-left: 2px; content: url(../images/icon-external-link.gif); }
a.restricted-link:after { padding-left: 2px; content: url(../images/icon-lock.png);}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试这样的事情时:
<a class="external-link restricted-link" href="some link">Some Link</a>
Run Code Online (Sandbox Code Playgroud)
它只显示最后一个图标,在本例中为icon-lock.png.这是有道理的,因为内容值只能设置一次不合并,所以最后一个类声明会覆盖它.无论如何要将这两者结合起来,以便我可以轻松地混合和匹配这些链接类(我总共有4个).我不想为每个组合制作单独的类/图像.
我的MVC应用程序存在一些问题,如果我的应用程序部署到域根以外的任何其他地方,则使用基于逻辑的数据驱动URL(用于路由).
我尝试使用各种Request.Url属性无济于事.
假设我将应用程序部署到www.mydomain.com/myapp/甚至是www.mydomain.com/myapp/subapp/.在这种情况下,我怎么能得到/myapp/和/myapp/subapp/分别.即使用户处于完全不同的页面上,例如/myapp/Users/Recent/?
我需要这样,所以我可以为所有数据驱动的URL添加前缀,这样我的应用程序在不在域根目录时仍可正常工作.
谢谢.
我试图公开EF代码首先在多对多关系中自动创建的链接类作为单独的对象,因为该链接对象需要在其他类中引用,但是我似乎遇到了获取存在于其他类中的数据的问题.数据库.
我有以下3个对象:
public class Role : Entity
{
public virtual ICollection<User> Users { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public virtual ICollection<Permission> Permissions { get; set; }
}
public class User: Entity
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Role> Roles { get; set; }
}
public class …Run Code Online (Sandbox Code Playgroud) 我有一个ListItem类,用于表示我的应用程序中的菜单项:
public class ListItem : Entity
{
public virtual List List { get; set; }
public virtual ListItem ParentItem { get; set; }
public virtual ICollection<ListItem> ChildItems { get; set; }
public int SortOrder { get; set; }
public string Text { get; set; }
public string Controller { get; set; }
public string Action { get; set; }
public string Area { get; set; }
public string Url { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我使用这些数据来构建应用程序的路由,但我想知道是否有一种干净的方法来处理静态内容的控制器/视图?基本上任何不使用任何数据而只是视图的页面.现在我有一个名为StaticContentController的控制器,它包含每个静态页面的唯一操作,返回适当的视图,如下所示:
public class StaticContentController : Controller …Run Code Online (Sandbox Code Playgroud) 我有一个Telerik MVC网格,我试图删除一个项目后重新绑定网格.
这是我的网格:
@(Html.Telerik().Grid(Model.Item).Name("Items").Sortable().Scrollable(x => x.Height(400)).Filterable().Pageable(x => x.PageSize(20))
.Pageable()
.Columns(columns =>
{
columns.Bound(x => x.Equipment.Location.Building.Name).Title("Building");
columns.Bound(x => x.Equipment.Location.Room).Width(150);
columns.Bound(x => x.Number).Title("Number").Width(150);
columns.Command(commands =>
{
if (Model.CanViewHistory)
{
commands
.Custom("ViewHistory")
.Text("History")
.ButtonType(GridButtonType.Text)
.SendState(false)
.DataRouteValues(x => x.Add(y => y.Id).RouteKey("id"))
.Action("Index", "ItemHistory");
}
if (Model.CanEdit)
{
commands
.Custom("Edit")
.Text("Edit")
.ButtonType(GridButtonType.Image).ImageHtmlAttributes(new { @class = "t-icon t-edit t-test" })
.DataRouteValues(x => x.Add(y => y.Id).RouteKey("id"))
.SendState(false)
.Action("Save", "Items");
commands
.Custom("Delete").HtmlAttributes(new { onclick = "return confirm('Are you sure you want to delete this item?')" })
.Text("Delete").Ajax(true)
.ButtonType(GridButtonType.Image).ImageHtmlAttributes(new …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×3
.net ×2
linq ×2
collections ×1
constructor ×1
controller ×1
css ×1
dynamic-linq ×1
generics ×1
linq-to-sql ×1
many-to-many ×1
routes ×1
telerik ×1
telerik-grid ×1
telerik-mvc ×1
vb.net ×1
where-clause ×1