C# MVC返回除完整模型以外的列列表
我创建了一个模型,其中包含一个名为“Customers”的表 它包含以下字段:C# MVC返回除完整模型以外的列列表,c#,visual-studio-2010,entity-framework,C#,Visual Studio 2010,Entity Framework,我创建了一个模型,其中包含一个名为“Customers”的表 它包含以下字段: 顾客档案 客户名称 生日 地址1 城市 陈述 拉链 CreatedOn 创造的 我对搜索表的存储过程(CustomerProfiles\u Search)进行了“函数导入”。(由于敏感信息,我无法发布存储过程)。“返回集合”设置为“实体:CustomerProfile”。它返回以下内容: 客户名称 生日 地址1 现在我感到困惑。我的控制器正在通过字段进行搜索,然后将其传递到我的“网关”,该网关返回一个列表 我
- 顾客档案
- 客户名称
- 生日
- 地址1
- 城市
- 陈述
- 拉链
- CreatedOn
- 创造的
- 客户名称
- 生日
- 地址1
public ActionResult GetRowCount(string CustomerName, string BirthDate, string Address1, string City, string State, string Zip)
{
List<CustomerProfile> searchResults = CustomerProfileGateway.Search(CustomerName, BirthDate, Address1, City, State, Zip);
int count = searchResults.Count();
string rowCount = count.ToString();
if (Request.IsAjaxRequest())
return Content(rowCount);
else
return RedirectToAction("Index", "OneView");
}
namespace Project.ABC.Objects
{
class SearchModel
{
public class SearchResults
{
public string CustomerName { get; set; }
public string BirthDate { get; set; }
public string Address1 { get; set; }
}
}
}
我想我需要创建一个返回内容的模型
我创建了以下内容:
public ActionResult GetRowCount(string CustomerName, string BirthDate, string Address1, string City, string State, string Zip)
{
List<CustomerProfile> searchResults = CustomerProfileGateway.Search(CustomerName, BirthDate, Address1, City, State, Zip);
int count = searchResults.Count();
string rowCount = count.ToString();
if (Request.IsAjaxRequest())
return Content(rowCount);
else
return RedirectToAction("Index", "OneView");
}
namespace Project.ABC.Objects
{
class SearchModel
{
public class SearchResults
{
public string CustomerName { get; set; }
public string BirthDate { get; set; }
public string Address1 { get; set; }
}
}
}
但我不知道怎么做?有人能告诉我我做错了什么吗。非常感谢您的帮助 问题在于,存储过程没有返回所需的所有列,而是说它应该映射到
CustomerProfile
当它试图从DataReader
读取属性时,找不到名为CustomerProfileID
的列,因此出现以下消息:
“CustomerProfileID”类型的成员在数据读取器中没有同名的对应列
您的
搜索结果
看起来不错。您只需将“返回集合”设置为“实体:搜索结果”这就是我试图做的,@Pedro。当我查看“实体”下拉菜单时,我的“搜索结果”不会显示在那里。我该如何做到这一点?我的SearchModel位于我的对象文件夹中,该文件夹中还有一个名为SVPModel.edmx的主模型。我哪里出错了?老实说,我从来没有用过UI。但是您的搜索结果是否应该继承自EntityObject
?尝试以下操作:注释您的搜索结果
,并在edmx设计器中使用所需的3个属性创建一个新实体。我想它应该能做到,但再说一次,我不是这方面的专家。。。