草庐IT

model1Instance

全部标签

c# - OData 和 WebAPI : Navigation property not present on model

我正在尝试使用EntityFramework、WebAPI、OData和Angular客户端组合一个简单的玩具项目。一切正常,除了我在其中一个模型上放置的导航属性似乎不起作用。当我使用$expand调用我的API时,返回的实体没有它们的导航属性。我的类是Dog和Owner,看起来像这样:publicclassDog{//Properties[Key]publicGuidId{get;set;}publicStringName{get;set;}[Required]publicDogBreedBreed{get;set;}publicintAge{get;set;}publicintWe

c# - “模型”与声明“System.Web.Mvc.WebViewPage<TModel>.Model”冲突

我想显示以下客户对象。publicClassCustomer{publiclongId{get;set;}publicstringName{get;set;}publicAddressAddressInfo{get;set;}}publicclassAddress{publicstringDetails{get;set;}publicCityCityInfo{get;set;}publicRegionRegionInfo{get;set;}}并且有一个Controller返回给客户查看publicActionResultGetCustomer(longId){returnView("C

c# - 尝试打开 telerik 报告时出现 "Value cannot be null. Parameter name: instance"错误

在我的解决方案中,我有telerik报告,当尝试在VisualStudio2010设计器中打开它们时,我收到此错误:Valuecannotbenull.Parametername:instanceCallStackatSystem.ComponentModel.TypeDescriptor.AddAttributes(Objectinstance,Attribute[]attributes)atMicrosoft.VisualStudio.Design.VSDesignSurface.CreateDesigner(IComponentcomponent,BooleanrootDesig

c# - Model 和 ViewModel 的验证最佳实践

我有单独的模型和View模型类。其中viewmodel类仅进行UI级别验证(引用:Validation:ModelorViewModel)。我可以在Controller中验证模型(vewmodel)是否有效。问:如何验证模型(带有数据注释的主要实体)。我没有使用模型对象开发View模型。只需复制属性并添加该特定View中可能需要的所有属性。//ModelClasspublicclassUser{[Required]publicstringEmail{get;set;}[Required]publicDateTimeCreated{get;set;}}//ViewModelClasspu

c# - 处理 ViewModel/Model 中的致命异常

我有一个使用M-V-VM方法编写的应用程序。数据访问在模型中完成。如果此处发生fatalerror(例如,与数据源的连接丢失),则抛出Exception。此异常冒泡到ViewModel。但是,因为数据访问的原始触发器是数据绑定(bind),WPF吞下了这个异常(它只在应用程序在调试器下运行时记录在输出窗口中)。我宁愿这个异常保持未处理状态,这样我的应用程序范围内的未处理异常处理程序就可以拾取它、记录它并优雅地退出。我怎样才能做到这一点? 最佳答案 您可以在调度程序上对异常抛出操作进行排队。//Thispropertyisconnec

c# - MVC3 全局化 : need global filter before model binding

目前,我有一个名为GlobalizationFilter的全局过滤器,它检查路由值、cookie和浏览器语言header以确定请求的正确文化设置:publicoverridevoidOnActionExecuting(ActionExecutingContextfilterContext){//determinecultureInfoThread.CurrentThread.CurrentCulture=cultureInfo;Thread.CurrentThread.CurrentUICulture=cultureInfo;}一切正常,但模型绑定(bind)过程似乎发生在全局过滤器之

C# 编译器错误 : "cannot have instance field initializers in structs"

我需要有关结构的建议。我有两段代码。第一部分如下:namespaceProject.GlobalVariables{classIOCard{structInputCard{publicstringCardNo;publicintBaseAddress;publicintLowerAddress;publicintUpperAddress;publicint[]WriteBitNo=newint[16];publicint[]ReadBitNo=newint[16];}staticInputCard[]InputCards=newInputCard[5];publicstaticstri

c# - "Object reference not set to an instance of an object": why can't . NET 显示更多细节?

“对象引用未设置到对象的实例”为什么异常不显示对象引用字段的名称,或者至少不显示它的类型?这可能是.NET中最常见的运行时错误之一。尽管System.Exception有堆栈跟踪,但没有其他有用的详细信息。在一年的时间里,我花了几个小时筛选堆栈跟踪(通常是在我没有编写的代码中),希望有一个来自“.pdb”文件的行号,然后在代码中找到该行,甚至那么该行中的哪个引用为空通常并不明显。拥有引用字段的名称会非常方便。如果System.ArgumentNullException实例可以显示方法参数的名称(“值不能为空。参数名称:值”),那么System.NullReferenceExceptio

c# - 如何在设计时避免 XAML 代码中出现 "object reference not set to an instance of an object"异常?

我自己设计的wpf用户控件有问题。问题是,当我在我的程序中实现用户控件时,在设计时XAML代码中出现objectreferencenotsettoaninstanceofanobject异常。设计师向我展示了以下信息:atMicrosoft.Expression.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Typetype,BooleansupportInternal)atMicrosoft.Expression.Platform.InstanceBuilders.ClrObjectInstan

c# - DropCreateDatabaseIfModelChanges EF6 导致 System.InvalidOperationException : The model backing the context has changed

迁移到EntityFramework6后,我在构建服务器上执行单元测试时遇到错误。我正在使用DropCreateDatabaseIfModelChanges初始化程序。当我将其更改为MigrateDatabaseToLatestVersion时一切正常,但我想坚持使用之前的初始化程序。我得到的错误是:System.InvalidOperationException:System.InvalidOperationException:Themodelbackingthe'AppContext'contexthaschangedsincethedatabasewascreated.Consi