- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我已经尝试修复这个错误一段时间了。
每当我的应用程序尝试创建我的数据上下文的实例时,我都会收到此错误。
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RandomRentals.Models;
using System.Data.Entity;
namespace RandomRentals.Models
{
public class RentalContext : DbContext
{
public DbSet<Rental> Rentals { get; set; }
public DbSet<Category> Categories { get; set; }
public DbSet<Item> Items { get; set; }
public DbSet<Billing> Billings { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<Video> Videos { get; set; }
public DbSet<Picture> Pictures { get; set; }
public DbSet<ServiceType> ServiceTypes { get; set; }
public DbSet<Rating> Ratings { get; set; }
public DbSet<Business> Businesses { get; set; }
public DbSet<BusinessHour> BusinessHours { get; set; }
}
}
这是堆栈跟踪:
[InvalidOperationException: The type 'RandomRentals.Rental' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.]
System.Data.Entity.Internal.DbSetDiscoveryService.GetSets() +706
System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets() +31
System.Data.Entity.DbContext.DiscoverAndInitializeSets() +56
System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model) +79
System.Data.Entity.DbContext..ctor() +99
RandomRentals.Models.RentalContext..ctor() +44
RandomRentals.Models.UserModel..ctor() in C:\Users\nikka\Desktop\RandomRentals\RandomRentals\Models\UserModel.cs:11
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +199
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +572
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +449
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
System.Web.Mvc.Controller.ExecuteCore() +116
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
这是完整的错误文本:
“RandomRentals.Rental”类型未映射。使用 Ignore 方法或 NotMappedAttribute 数据注释检查是否未明确排除该类型。验证该类型是否定义为类,不是原始类型、嵌套类型或泛型类型,并且不是从 EntityObject 继承的。
编辑:租赁类代码。
[EdmEntityTypeAttribute(NamespaceName="DevelopmentModel", Name="Rental")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
公共(public)部分类 Rental : EntityObject{ #region 工厂方法
/// <summary>
/// Create a new Rental object.
/// </summary>
/// <param name="rentalID">Initial value of the RentalID property.</param>
/// <param name="agreedPrice">Initial value of the AgreedPrice property.</param>
/// <param name="rentedOn">Initial value of the RentedOn property.</param>
/// <param name="rentalDays">Initial value of the RentalDays property.</param>
/// <param name="returned">Initial value of the Returned property.</param>
/// <param name="rentedBy">Initial value of the RentedBy property.</param>
/// <param name="returnedOn">Initial value of the ReturnedOn property.</param>
/// <param name="ownerReviewed">Initial value of the OwnerReviewed property.</param>
/// <param name="billingID">Initial value of the BillingID property.</param>
/// <param name="itemID">Initial value of the ItemID property.</param>
/// <param name="categoryDescription">Initial value of the CategoryDescription property.</param>
/// <param name="title">Initial value of the Title property.</param>
public static Rental CreateRental(global::System.Int32 rentalID, global::System.Decimal agreedPrice, global::System.DateTime rentedOn, global::System.Int32 rentalDays, global::System.Boolean returned, global::System.Int32 rentedBy, global::System.DateTime returnedOn, global::System.Boolean ownerReviewed, global::System.Int32 billingID, global::System.Int32 itemID, global::System.String categoryDescription, global::System.String title)
{
Rental rental = new Rental();
rental.RentalID = rentalID;
rental.AgreedPrice = agreedPrice;
rental.RentedOn = rentedOn;
rental.RentalDays = rentalDays;
rental.Returned = returned;
rental.RentedBy = rentedBy;
rental.ReturnedOn = returnedOn;
rental.OwnerReviewed = ownerReviewed;
rental.BillingID = billingID;
rental.ItemID = itemID;
rental.CategoryDescription = categoryDescription;
rental.Title = title;
return rental;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 RentalID
{
get
{
return _RentalID;
}
set
{
if (_RentalID != value)
{
OnRentalIDChanging(value);
ReportPropertyChanging("RentalID");
_RentalID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RentalID");
OnRentalIDChanged();
}
}
}
private global::System.Int32 _RentalID;
partial void OnRentalIDChanging(global::System.Int32 value);
partial void OnRentalIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Decimal> ProposedPrice
{
get
{
return _ProposedPrice;
}
set
{
OnProposedPriceChanging(value);
ReportPropertyChanging("ProposedPrice");
_ProposedPrice = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ProposedPrice");
OnProposedPriceChanged();
}
}
private Nullable<global::System.Decimal> _ProposedPrice;
partial void OnProposedPriceChanging(Nullable<global::System.Decimal> value);
partial void OnProposedPriceChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Decimal AgreedPrice
{
get
{
return _AgreedPrice;
}
set
{
OnAgreedPriceChanging(value);
ReportPropertyChanging("AgreedPrice");
_AgreedPrice = StructuralObject.SetValidValue(value);
ReportPropertyChanged("AgreedPrice");
OnAgreedPriceChanged();
}
}
private global::System.Decimal _AgreedPrice;
partial void OnAgreedPriceChanging(global::System.Decimal value);
partial void OnAgreedPriceChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.DateTime RentedOn
{
get
{
return _RentedOn;
}
set
{
OnRentedOnChanging(value);
ReportPropertyChanging("RentedOn");
_RentedOn = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RentedOn");
OnRentedOnChanged();
}
}
private global::System.DateTime _RentedOn;
partial void OnRentedOnChanging(global::System.DateTime value);
partial void OnRentedOnChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 RentalDays
{
get
{
return _RentalDays;
}
set
{
OnRentalDaysChanging(value);
ReportPropertyChanging("RentalDays");
_RentalDays = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RentalDays");
OnRentalDaysChanged();
}
}
private global::System.Int32 _RentalDays;
partial void OnRentalDaysChanging(global::System.Int32 value);
partial void OnRentalDaysChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Boolean Returned
{
get
{
return _Returned;
}
set
{
OnReturnedChanging(value);
ReportPropertyChanging("Returned");
_Returned = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Returned");
OnReturnedChanged();
}
}
private global::System.Boolean _Returned;
partial void OnReturnedChanging(global::System.Boolean value);
partial void OnReturnedChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 RentedBy
{
get
{
return _RentedBy;
}
set
{
OnRentedByChanging(value);
ReportPropertyChanging("RentedBy");
_RentedBy = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RentedBy");
OnRentedByChanged();
}
}
private global::System.Int32 _RentedBy;
partial void OnRentedByChanging(global::System.Int32 value);
partial void OnRentedByChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.DateTime ReturnedOn
{
get
{
return _ReturnedOn;
}
set
{
OnReturnedOnChanging(value);
ReportPropertyChanging("ReturnedOn");
_ReturnedOn = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ReturnedOn");
OnReturnedOnChanged();
}
}
private global::System.DateTime _ReturnedOn;
partial void OnReturnedOnChanging(global::System.DateTime value);
partial void OnReturnedOnChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Boolean OwnerReviewed
{
get
{
return _OwnerReviewed;
}
set
{
OnOwnerReviewedChanging(value);
ReportPropertyChanging("OwnerReviewed");
_OwnerReviewed = StructuralObject.SetValidValue(value);
ReportPropertyChanged("OwnerReviewed");
OnOwnerReviewedChanged();
}
}
private global::System.Boolean _OwnerReviewed;
partial void OnOwnerReviewedChanging(global::System.Boolean value);
partial void OnOwnerReviewedChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public global::System.String RenterFeedback
{
get
{
return _RenterFeedback;
}
set
{
OnRenterFeedbackChanging(value);
ReportPropertyChanging("RenterFeedback");
_RenterFeedback = StructuralObject.SetValidValue(value, true);
ReportPropertyChanged("RenterFeedback");
OnRenterFeedbackChanged();
}
}
private global::System.String _RenterFeedback;
partial void OnRenterFeedbackChanging(global::System.String value);
partial void OnRenterFeedbackChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 BillingID
{
get
{
return _BillingID;
}
set
{
OnBillingIDChanging(value);
ReportPropertyChanging("BillingID");
_BillingID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("BillingID");
OnBillingIDChanged();
}
}
private global::System.Int32 _BillingID;
partial void OnBillingIDChanging(global::System.Int32 value);
partial void OnBillingIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 ItemID
{
get
{
return _ItemID;
}
set
{
OnItemIDChanging(value);
ReportPropertyChanging("ItemID");
_ItemID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ItemID");
OnItemIDChanged();
}
}
private global::System.Int32 _ItemID;
partial void OnItemIDChanging(global::System.Int32 value);
partial void OnItemIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String CategoryDescription
{
get
{
return _CategoryDescription;
}
set
{
OnCategoryDescriptionChanging(value);
ReportPropertyChanging("CategoryDescription");
_CategoryDescription = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("CategoryDescription");
OnCategoryDescriptionChanged();
}
}
private global::System.String _CategoryDescription;
partial void OnCategoryDescriptionChanging(global::System.String value);
partial void OnCategoryDescriptionChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Title
{
get
{
return _Title;
}
set
{
OnTitleChanging(value);
ReportPropertyChanging("Title");
_Title = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Title");
OnTitleChanged();
}
}
private global::System.String _Title;
partial void OnTitleChanging(global::System.String value);
partial void OnTitleChanged();
#endregion
}
任何帮助将不胜感激
最佳答案
我也遇到了同样的问题,希望得到解答。但是没有快乐!所以我一直在寻找 - 在 Pluralsight 上有关于 Entity Framework 的培训视频。我找到了问题的答案。我试图将 DbContext 与数据库生成的 .edmx 模型一起使用。 (不是代码优先)因此我需要将 .edmx 文件中的默认代码生成模板切换为 Ado.NET DbContext Generator。我还必须下载它,因为当我右键单击 .edmx 设计器表面并选择“添加代码生成项”时,它不在我看到的代码生成器列表中从这里下载:download EF 4.x DbContext Generator for C#或这里 for 5.x - check out this link.
因此,在我将其作为 .edmx 文件的代码生成项安装后,并向我的类添加了一个构造函数,该构造函数派生自 DbContext,它命名我的连接字符串
public class ContentRepository: DbContext
{
public DbSet<Content_Template> content_Templates { get; set; }
public DbSet<Master_Template> master_Templates { get; set; }
public DbSet<Master_Content_Map> master_Content_Maps { get; set; }
public ContentRepository()
: base("name=MessagingSystemEntities")
{
}
我的问题解决了。也许它也会对您有所帮助,我希望如此。
关于c# - 类型 '' 未映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13427803/
我正在尝试编写一个相当多态的库。我遇到了一种更容易表现出来却很难说出来的情况。它看起来有点像这样: {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE
谁能解释一下这个表达式是如何工作的? type = type || 'any'; 这是否意味着如果类型未定义则使用“任意”? 最佳答案 如果 type 为“falsy”(即 false,或 undef
我有一个界面,在IAnimal.fs中, namespace Kingdom type IAnimal = abstract member Eat : Food -> unit 以及另一个成功
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: What is the difference between (type)value and type(va
在 C# 中,default(Nullable) 之间有区别吗? (或 default(long?) )和 default(long) ? Long只是一个例子,它可以是任何其他struct类型。 最
假设我有一个案例类: case class Foo(num: Int, str: String, bool: Boolean) 现在我还有一个简单的包装器: sealed trait Wrapper[
这个问题在这里已经有了答案: Create C# delegate type with ref parameter at runtime (1 个回答) 关闭 2 年前。 为了即时创建委托(dele
我正在尝试获取图像的 dct。一开始我遇到了错误 The function/feature is not implemented (Odd-size DCT's are not implemented
我正在尝试使用 AFNetworking 的 AFPropertyListRequestOperation,但是当我尝试下载它时,出现错误 预期的内容类型{( “应用程序/x-plist” )}, 得
我在下面收到错误。我知道这段代码的意思,但我不知道界面应该是什么样子: Element implicitly has an 'any' type because index expression is
我尝试将 SignalType 从 ReactiveCocoa 扩展为自定义 ErrorType,代码如下所示 enum MyError: ErrorType { // .. cases }
我无法在任何其他问题中找到答案。假设我有一个抽象父类(super class) Abstract0,它有两个子类 Concrete1 和 Concrete1。我希望能够在 Abstract0 中定义类
我想知道为什么这个索引没有用在 RANGE 类型中,而是用在 INDEX 中: 索引: CREATE INDEX myindex ON orders(order_date); 查询: EXPLAIN
我正在使用 RxJava,现在我尝试通过提供 lambda 来订阅可观察对象: observableProvider.stringForKey(CURRENT_DELETED_ID) .sub
我已经尝试了几乎所有解决问题的方法,其中包括。为 提供类型使用app.use(express.static('public'))还有更多,但我似乎无法为此找到解决方案。 index.js : imp
以下哪个 CSS 选择器更快? input[type="submit"] { /* styles */ } 或 [type="submit"] { /* styles */ } 只是好
我不知道这个设置有什么问题,我在 IDEA 中获得了所有注释(@Controller、@Repository、@Service),它在行号左侧显示 bean,然后转到该 bean。 这是错误: 14-
我听从了建议 registering java function as a callback in C function并且可以使用“简单”类型(例如整数和字符串)进行回调,例如: jstring j
有一些 java 类,加载到 Oracle 数据库(版本 11g)和 pl/sql 函数包装器: create or replace function getDataFromJava( in_uLis
我已经从 David Walsh 的 css 动画回调中获取代码并将其修改为 TypeScript。但是,我收到一个错误,我不知道为什么: interface IBrowserPrefix { [
我是一名优秀的程序员,十分优秀!