simple MVC EF query
I am a MVC EF newb.
I'm trying to do a very simple query. Maybe I'm thinking about it too much in the "SELECT * FROM TABLE WHERE BLAHBLAH > 3" format and not in a class-based MVC EF layout.
Anyway I have a model/class called "Messages". I'm trying to get all the messages with a specific username. So I have something like this:
var mesg = from msg in elkdb.Messages
where mydb.Messages.user = Membership.GetUser()
select msg;
Visual web developer flags the .msg part of the "where" line and says:
Error 2 'System.Data.Entity.DbSet' does not contain a definition for 'msg' and no ex开发者_StackOverflowtension method 'msg' accepting a first argument of type 'System.Data.Entity.DbSet' could be found (are you missing a using directive or an assembly reference?)
msg is defined in the class as follows:
public class Message
{
public long ID { get; set; }
...
public string msg { get; set; }
}
And I know I have scope access to Message at this point.
Am I laying this out wrong? Do I just have the syntax incorrect?
Thanks for your help!
EDIT: I mistakenly had "mydb.Messages.msg = Membership.GetUser()" earlier because it was way past my bedtime.
I think the query are wrong
var mesg = from MSG in elkdb.Messages
where MSG.msg == Membership.GetUser()
select MSG;
does the msg prop match with UserName?
精彩评论