Trying to Understand class
I'm trying to understand the concept of class when I'm using db ,(mvc 3) adding a class using the same name of any of my db table always give me error saying Mi开发者_如何学Pythonssing partial modifier on declaration of type MySite.Models.computers'; another partial declaration of this type exists, so how am I suppose to do it ? I'm trying to do something like this:
public class computers
{
public int ID { get; set; }
// public IEnumerable<computers> computers { get; set; }
// i would like to have this parameter a IEnumerable <price>
// -in my db this is a string
}
Sounds like you already have a LinqToSql database context in your project.
changing
public class computers
{
...
}
to
public partial class computers
{
...
}
will let your project build, but without further information, it's hard to tell if that's really what you're trying to do.
You're using some kind of tool (Entity Framework, Linq-to-SQL, etc) that's generating a class for you. It will be generated as a partial class like this:
public partial class computers { ... }
The reason it does this is that you might want to include some logic into that class. So, the tool makes it partial
and then you can define another partial
class in the same folder. The compiler will merge the two of them for you at build time.
However if you try to make another class in the same folder called computer without defining it as partial
, it's an error. You cannot have two classes with the same name in the same folder (namespace). Two partial
classes are find though, because they are really the same class after they're merged.
I doubt this is anything to do with MVC.
精彩评论