问题描述
我在做什么是数据库简单的DML操作。我有简单的菜单表,其中我想存储菜单。我的菜单模式
what I am doing is simple DML operation in database. I have simple menu table where I want to store menus. my model for menu is
public class utblMenuMaster
{
[Key]
[HiddenInput(DisplayValue = false)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public long MenuID { get; set; }
public string MenuName { get; set; }
public string MenuDesc { get; set; }
public bool IsVisible { get; set; }
public bool IsDynamic { get; set; }
public string MenuPosition { get; set; }
public string AdminUrl { get; set; }
public string PublicUrl { get; set; }
public string UserID { get; set; }
public string NoContentColumn { get; set; }
public string NoContentColumn1 { get; set; }
public string NoContentColumn2 { get; set; }
public string NoContentColumn3 { get; set; }
}
我的数据库表列如下: -
My Database table columns are as follows:-
MenuID
MenuName
MenuDesc
IsVisible
IsDynamic
MenuPosition
AdminUrl
PublicUrl
UserID
NoContentColumn
NoContentColumn1
NoContentColumn2
NoContentColumn3
现在,当我试图选择这样从 utblMenuMaster
数据
Now when I tries to select data from utblMenuMaster
like this
MenuMaster = objDB.utblMenuMasters.FirstOrDefault(x => x.MenuID == MenuID);
然后我收到
'System.InvalidOperationException'类型的异常出现在EntityFramework.dll但在用户code没有处理
An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
更多信息:酒店MENUID'不能被配置为导航属性。该物业必须是有效的实体类型和属性应该有一个非抽象的getter和setter。对于集合属性的类型必须实现ICollection的,其中T是一个有效的实体类型。
Additional information: The property 'MenuID' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type.
我知道我错了,在模型和框架提的一些地方。我怎么能在这个表上执行DML。我是新来的MVC平台可能是我没有正确配置模式。
I know I am wrong some where in mentioning in the model and Framework. How can I perform DML in this table. I am new to the MVC platform may be I am not configuring the model properly.
推荐答案
在我的情况,我刚才已经作出新的项目,并取得了新的 Efdbcontext
和正常工作。错误背后的原因是,在 Efdbcontext
(其已被复制)具有另一项目,由其所产生问题的一个参考。希望这是有帮助的。
In My case, I have just make new project and made new Efdbcontext
and works fine. the reason behind the error is that the Efdbcontext
(which has been copied) has a reference of another project, by which it is creating problem. Hope this is helpful.
这篇关于该属性不能被配置为一个导航属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!