本文将介绍C#访问ManagementObjectCollection中的管理对象的详细情况,特别是关于c#访问类型的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时
本文将介绍C#访问ManagementObjectCollection中的管理对象的详细情况,特别是关于c#访问类型的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ARObjectCollectionViewController、c# – ObjectStateManager不包含ObjectStateEntry,它引用了类型的对象、Call to a member function fetchColumn() on a non-object的知识。
本文目录一览:- C#访问ManagementObjectCollection中的管理对象(c#访问类型)
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- ARObjectCollectionViewController
- c# – ObjectStateManager不包含ObjectStateEntry,它引用了类型的对象
- Call to a member function fetchColumn() on a non-object
C#访问ManagementObjectCollection中的管理对象(c#访问类型)
ManagementObjectSearcher query = new ManagementObjectSearcher( "select Name,CurrentClockSpeed from Win32_Processor"); ManagementObjectCollection queryCollection = query.Get(); ManagementObject mo = queryCollection[0];
解决方法
但是因为它支持IEnumerable,所以你可以使用Linq:
ManagementObject mo = queryCollection.OfType<ManagementObject>().FirstOrDefault()
OfType<&的ManagementObject GT;是必需的,因为ManagementObjectCollection支持IEnumerable但不支持IEnumerable of T.
angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])
我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.
我试图像这样在appService中注入第一个authService但是得到了同样的错误
@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService
我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的
如果有人可以帮我处理它,我很感激.
Angular 4.0.0
AuthService
import { Injectable } from '@angular/core'; import {Http,Headers,Response} from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; import {AppServices} from "../../app.services"; import {Router} from "@angular/router"; @Injectable() export class AuthenticationService { public token: any; constructor( private http: Http,private appService: AppServices,private router: Router ) { this.token = localStorage.getItem('token'); } login(username: string,password: string): Observable<boolean> { let headers = new Headers(); let body = null; headers.append("Authorization",("Basic " + btoa(username + ':' + password))); return this.http.post(this.appService.api + '/login',body,{headers: headers}) .map((response: Response) => { let token = response.json() && response.json().token; if (token) { this.token = token; localStorage.setItem('Conform_token',token); return true; } else { return false; } }); } logout(): void { this.token = null; localStorage.removeItem('Conform_token'); this.router.navigate(['/login']); } }
应用服务
import {Injectable} from '@angular/core'; import {Headers,Http,RequestOptions} from '@angular/http'; import {Router} from "@angular/router"; import {AuthenticationService} from "./auth/auth.service"; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; @Injectable() export class AppServices { api = '//endpoint/'; public options: any; constructor( private http: Http,private router: Router,public authService: AuthenticationService // doesn't work // @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either ) { let head = new Headers({ 'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8" }); this.options = new RequestOptions({headers: head}); } // ==================== // data services // ==================== getData(): Promise<any> { return this.http .get(this.api + "/data",this.options) .toPromise() .then(response => response.json() as Array<Object>) .catch((err)=>{this.handleError(err);}) }
应用模块
import { browserModule } from '@angular/platform-browser'; import { browserAnimationsModule } from '@angular/platform-browser/animations'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import {BaseRequestOptions,HttpModule} from '@angular/http'; import { MaterialModule} from '@angular/material'; import {FlexLayoutModule} from "@angular/flex-layout"; import 'hammerjs'; import { routing,appRoutingProviders } from './app.routing'; import { AppServices } from './app.services'; import {AuthGuard} from "./auth/auth.guard"; import {AuthenticationService} from "./auth/auth.service"; import {AppComponent} from './app.component'; import {AuthComponent} from './auth/auth.component'; import {NotFoundComponent} from './404/not-found.component'; import { HomeComponent } from './home/home.component'; @NgModule({ declarations: [ AppComponent,AuthComponent,NotFoundComponent,HomeComponent ],imports: [ browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent] }) export class AppModule { }
解决方法
你可以使用
export class AuthenticationService { public token: any; appService: AppServices; constructor( private http: Http,// private appService: AppServices,injector:Injector; private router: Router ) { setTimeout(() => this.appService = injector.get(AppServices)); this.token = localStorage.getItem('token'); }
另见DI with cyclic dependency with custom HTTP and ConfigService
要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)
ARObjectCollectionViewController
ARObjectCollectionViewController 介绍
ARObjectCollectionViewController 是 UIViewController,可以展示 JSON Nsstring,JSON
NSData, JSON URL, XML NSData, XML URL, RSS NSData, RSS URL, NSDictionary,
NSArray, NSSet, UIImage EXIF 元数据等等。
ARObjectCollectionViewController 官网
http://www.alexruperez.com/repos/25-arobjectcollectionviewcontroller
c# – ObjectStateManager不包含ObjectStateEntry,它引用了类型的对象
int apId = Convert.ToInt32(Request.QueryString["ApplicationID"]); ApplicationBLL objGetApplication = new ApplicationBLL(); Appdec.YEP.BusinessEntities.Application objApplication = objGetApplication.GetApplicationByApplicationID(apId); objApplication.Status = (ddlStatus.SelectedValue == "0" ? false : true); new ApplicationBLL(new Appdec.YEP.DataAccessLayer.DatabaseContext()).UpdateApplication(objApplication);
现在商务逻辑的更新方法是
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update,true)] public void UpdateApplication(Application updatedApplication) { // Validate Parameters if (updatedApplication == null) throw (new ArgumentNullException("updatedApplication")); // Validate Primary key value if (updatedApplication.ApplicationID.IsInvalidKey()) BusinessLayerHelper.ThrowErrorForInvalidDataKey("ApplicationID"); // Apply business rules OnApplicationSaving(updatedApplication); OnApplicationUpdating(updatedApplication); //attaching and making ready for parsistance if (updatedApplication.EntityState == EntityState.Detached) _DatabaseContext.Applications.Attach(updatedApplication); _DatabaseContext.ObjectStateManager.ChangeObjectState(updatedApplication,System.Data.EntityState.Modified);//this line throws the error //ObjectStateManager does not contain an ObjectStateEntry with a reference to an object of type int numberOfAffectedRows = _DatabaseContext.SaveChanges(); if (numberOfAffectedRows == 0) throw new DatanotUpdatedException("No application updated!"); //Apply business workflow OnApplicationUpdated(updatedApplication); OnApplicationSaved(updatedApplication); }
有人可以告诉我如何修复此错误并更新表.
当我尝试更新其他表时,同样的错误发生.插件工作正常.
希望不要打扰你.最好的祝福.
解决方法
它不能附加到新的背景,
您可以创建updatedApplication的新实例,并将updatedApplication的所有属性复制到此新实例,并将新实体附加到应用程序.
也改变
if (newApp .EntityState == EntityState.Detached) _DatabaseContext.Applications.Attach(newApp );
至
var newApp = Application (); //copy all propery of updatedApplication to newApp here if (newApp .EntityKey == null || newApp .EntityKey.Istemporary) { _DatabaseContext.Applications.Addobject(newApp ); } else { _DatabaseContext.Applications.Attach(newApp ); } _DatabaseContext.ObjectStateManager.ChangeObjectState(newApp,System.Data.EntityState.Modified);
Call to a member function fetchColumn() on a non-object
采用 pdo 方式连接 mysql
$rs=$conn->query("select count(*) from member where id=0 "); $res=$conn->query("select count(*) from member where mess=0 "); $total = $rs->fetchColumn(); $res_total = $res->fetchColumn();不知道为什么提示 Call to a member function fetchColumn () on a non-object 而且是第二个 fetchColumn () ,为什么第一个 fetchColumn () 不出错呢?$total 也有值,很奇怪
关于C#访问ManagementObjectCollection中的管理对象和c#访问类型的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ARObjectCollectionViewController、c# – ObjectStateManager不包含ObjectStateEntry,它引用了类型的对象、Call to a member function fetchColumn() on a non-object的相关信息,请在本站寻找。
本文标签: