草庐IT

non_model_field

全部标签

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - MVC 错误 : The model item passed into the dictionary is null

我只是想建立一个View,但我收到以下错误:System.InvalidOperationException:Themodelitempassedintothedictionaryisnull,butthisdictionaryrequiresanon-nullmodelitemoftype'System.DateTime现在,我知道为什么会出现这种情况,数据库中的特定字段是空值,但它应该是空值,因为这是稍后编辑的内容。这是我的代码:ActionpublicActionResultView(Int64?Id){ModelContainerctn=newModelContainer();

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - 当部分 View 位于共享文件夹中时,ASP.NET MVC '@model dynamic' 无法识别模型属性

不重复:MVCRazordynamicmodel,'object'doesnotcontaindefinitionfor'PropertyName'根据那里的答案,AccordingtoDavidEbbo,youcan'tpassananonymoustypeintoadynamically-typedviewbecausetheanonymoustypesarecompiledasinternal.SincetheCSHTMLviewiscompiledintoaseparateassembly,itcan'taccesstheanonymoustype'sproperties.为什

c# - WCF 反序列化中的 XmlException : "Name cannot begin with ' <'" - in automatic property backing fields

我今天开始在WCF反序列化中遇到错误-代码一直没有改变并且工作了几个月。问题是我正在获取运行时XmlException说“名称不能以‘k_BackingField,这是XmlException的来源。我在网上看到了其他一些引用资料,其中人们接受的解决方案是“我更改了我的代码以不使用自动属性”,这对我来说是不能接受的,因为我需要更改100个对象,(其中有1000个属性)。此外,当我上周运行这段相同的代码时,它运行良好,似乎并没有影响所有序列化的DTO,只有一些。更令人沮丧的是,它似乎有点断断续续。今天早上偶尔会抛出异常...!问题;为什么在未更改的代码和未更改的框架源中突然出现此问题?如

c# - 扩展 ASP.NET 身份角色 : IdentityRole is not part of the model for the current context

我正在尝试在我的MVC5应用程序中使用新的ASP.NETIdentity,特别是我正在尝试将ASP.NETIdentity集成到现有数据库中。我已经阅读了有关DBFirst和ASP.NETIdentity的SO问题/答案,并且遵循了所有建议我仍然无法向我的数据库添加角色,尽管我在添加用户时没有问题。这是我的代码:varcontext=newPayrollDBEntities();varroleManager=newRoleManager(newRoleStore(context));boolroleExists=roleManager.RoleExists(roleDto.Name);

c# - ASP.NET MVC : Views using a model type that is loaded by MEF can't be found by the view engine

我正在尝试创建一个框架,以允许将Controller和View动态导入到MVC应用程序中。到目前为止,它是这样工作的:我正在使用.NET4、ASP.NETMVC3RC和RazorViewEngine每个项目都使用MEF导出和导入Controller-我将给定项目中的一组Controller和View称为“模块”BuildManager使用应用前启动方法和BuildManager.AddReferencedAssembly动态引用使用MEF发现的程序集。使用构建事件将二进制文件(来自导出项目)和View复制到目标项目的文件夹结构中使用自定义Controller工厂选择Controller

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# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

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