我是C#的初学者,但我在搜索中找不到解决方案。
我有一个数据库模型(EDM)。
我已经在models文件夹中创建了一个类文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace photostorage.Models
{
public class PhotosRepository
{
private fotostorageEntities db = new fotostorageEntities();
public IEnumerable<photos> FindUserPhotos(string userid)
{
return from m in db.photos
select m;
}
public photos GetPhotosById(int photoid)
{
return db.photos.SingleOrDefault(d => d.id == photoid);
}
}
}
下一步,我创建了一个控制器来管理这个模型:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using photostorage.Models;
namespace photostorage.Controllers
{
public class PhotosController : Controller
{
//
// GET: /Photos/
public ActionResult ViewPhoto(string userid, int photoid)
{
photos CurrentPhoto = PhotosRepository.GetPhotosById(photoid);
if (CurrentPhoto == null)
return View("NotFound");
else
return View("ViewPhoto", CurrentPhoto);
}
}
}
在结果中出现错误:未对非静态字段、方法或属性photostorage.Models.PhotosRepository.GetPhotosById(int)进行对象引用。
数据库中的表名为photos EDM连接字符串名称为fotostorageEntities。
需要帮助,因为我真的不知道解决方法。