Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've followed Adam's answer here and the Entity Framework now works and the Seed() method also works.

But when I try to access the database like this:

    public User FindUserByID(int id)
    {
        return (from item in this.Users
                where item.ID == id
                select item).SingleOrDefault();
    }
  .............................................................................
    // GET: /Main/

    public ActionResult Index(int? id)
    {
        var db = UserDataBaseDB.Create();

        if (!id.HasValue)
            id = 0;

        return View(db.FindUserByID(id.Value));
    }

It throws an exception at return (from item in this.Users stating:

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.BaseCs'.

I've tried replacing it with: return this.Users.ElementAt(id); but then it throws this exception.

LINQ to Entities does not recognize the method 'MySiteCreator.Models.User ElementAt[User](System.Linq.IQueryable1[MySiteCreator.Models.User], Int32)' method, and this method cannot be translated into a store expression.`

Can anyone help me?
Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
293 views
Welcome To Ask or Share your Answers For Others

1 Answer

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'dbo.BaseCs'

This error means that EF is translating your LINQ into a sql statement that uses an object (most likely a table) named dbo.BaseCs, which does not exist in the database.

Check your database and verify whether that table exists, or that you should be using a different table name. Also, if you could post a link to the tutorial you are following, it would help to follow along with what you are doing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...