Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要实体框架来忽略模型成员_C#_Vb.net_Asp.net Mvc 3_Entity Framework - Fatal编程技术网

C# 需要实体框架来忽略模型成员

C# 需要实体框架来忽略模型成员,c#,vb.net,asp.net-mvc-3,entity-framework,C#,Vb.net,Asp.net Mvc 3,Entity Framework,我们需要存储从另一个表中提取的数据列表,该表与我们的一个模型相关。(我们对构建的了解太深,无法将此关系添加到数据库中的适当位置。)当我们尝试将此列表加载到需要它的模型的属性中时 我们将此列表加载到视图中的下拉列表中。尝试将此列表加载到控制器中的模型时出错。真正需要注意的是,对于视图中表中的每条记录,我们都有一个唯一的下拉列表 我们班: Public class OurModel public property ID As Integer Public property First As

我们需要存储从另一个表中提取的数据列表,该表与我们的一个模型相关。(我们对构建的了解太深,无法将此关系添加到数据库中的适当位置。)当我们尝试将此列表加载到需要它的模型的属性中时

我们将此列表加载到视图中的下拉列表中。尝试将此列表加载到控制器中的模型时出错。真正需要注意的是,对于视图中表中的每条记录,我们都有一个唯一的下拉列表

我们班:

Public class OurModel
  public property ID As Integer
  Public property First As Integer
  Public property Last As Integer
  Public property myList As List(Of SelectListItem)//This is our problem member
End class
控制器:

                         //This ViewModel is what we pass around from page to page to populate the various elements we need that is not tied to a specific model
Public Function LoadList(myViewModel As ViewModel) As Action Result
   Using db //our database resource 
    For i As Integer = 0 to myViewModel.OurModel
       //Assume table select statement previously declared and initialized into dbGet
       **NOTE: dbGet is retieving data from a different table that is tied to this Model**
       dbGet = dbGet.Where(Function(x) x.ID = myViewModel.OurModel.ID)
       myViewModel.OurModel.myList = dbGet.ToList().[Select](Function(x) New SelectListItem() With {.Value = x.number, .Text = x.number})//ERROR IS HERE
    Next
   End Using
End Function
错误:

LINQ to Entities无法识别“DB.ModelTable get_Item(Int32)”方法,并且无法将此方法转换为存储表达式。


更新:问题似乎是LINQ正在尝试使用我以前在此控制器中执行的查询的DBContext执行某些操作。错误引用的是
DB.Employee
而不是
DB.Position
,这正是我要查询的。

我在VB.Net中几乎什么都没做,但听起来get_项(Int32)可能与C#中的索引器相同

存在一个众所周知的缺点,即实体框架不支持包含索引器的类(即使您使用
NotMapped
装饰该属性)

我面临着一个类似的问题,那就是实现一个可锁定的ObservableCollection。我发现我无法实现
IList
,因为存在错误,但我可以实现
ICollection


如果可以用集合的语义替换列表的语义,那么应该可以解决这个问题。

我最后不得不编写新的类,这些类连接到实体框架之外的数据库。如果您想使用实体框架,请在开始构建应用程序之前确保您的数据库设计是完美的,祝您好运。

当我们将此应用程序放入模型时,我们也遇到了同样的错误。我认为我们不能将其放入视图模型中,因为它不可“索引”,我们无法将其与模型列表中的特定实例相关联。如果我们尝试将其存储在ViewModel或ViewBag中,我们会遇到相同的错误。EF不喜欢列表的概念。