Recently prepared to re-design the background management system, the use of bootstrap, in the Internet to find a beautiful backstage template: Sb2-admin, in the use of a lot of problems encountered, summarized under, lest forget later.
1, EF5 after using NuGet to upgrade to EF6, some attribute conflicts [unresolved]:
My original data driver was using fluent Nhibernate +nhibernate+mssql2005, who wanted to play EF, and now comes with EF in the newly created MVC project template. Because EF5 does not support project templates to generate code first, it has been upgraded to EF6, which is a hassle after setting up to upgrade. "System.ComponentModel.DataAnnotations" This namespace exists in 2 DLLs at the same time, originally my idea is very simple, I do not reference the good, can delete the reference, or prompt the conflict. Later I think it may be webconfig or the package has a problem, can be checked for half a day or no problem. Group of friends said is the problem of caching, restarted the iisexpress, restart the computer, there is no way to solve, there is no way to abandon the EF way, or use the original data-driven. (PS: Which heroes have a solution, you can leave a message, the main conflict is tableattribute and other marked characteristics)
2. Fluentnhibernate does not support stored procedures
Always thought that the operation of the stored procedure is not using FN, this time because the back page to statistics, the use of stored procedures, but found in the use of FN currently does not support stored procedures (click to view the official), there is no way, can only use fluent configuration and HBM The mapping method for configuration blending.
Here's what to note:
A) The data returned by the stored procedure, preferably redefining a class, and mapping (can use FN or HDM mode)
b) put the newly defined class and the mapped hbm files on your model layer for easy management later.
c) Map the HDM file name of the stored procedure, named after the name of the return type. (If the returned class is named: DATARESULT,HBM's file name is: DataResult.hbm.xml)
Class
Public classTraveldefaultdata{ Public Virtual intUserCount {Get; Set; } Public Virtual intOrderCount {Get; Set; } Public Virtual intLineCount {Get; Set; } Public Virtual intCrusisecount {Get; Set; } }
Hbm
<?XMLversion="1.0" encoding="Utf-8" ?><hibernate-mappingxmlns="urn:nhibernate-mapping-2.2" Assembly="Travel.domain" namespace="Bus.travel"> <Sql-queryname="Gettraveldata"> <returnclass="Traveldefaultdata"> <Return-propertycolumn="UserCount" name="UserCount" /> <Return-propertycolumn="OrderCount" name="OrderCount" /> <Return-propertycolumn="LineCount" name="Lincrusisecount" /> </return>EXEC [Gettraveldata]: userstartdate,: orderstartdate,: linestartdate,: Crusiesstartdate</Sql-query></hibernate-mapping>
Traveldefaultdata map, you can refer to here.
Finally, remember to configure the hybrid mapping:
var fluently areamap > (); A.hbmmappings.addclasses ( typeof ( traveldefaultdata return Db. Buildsessionfactory ();
The configuration can then be used in a nhibernate manner.
3. When using the Web API, return type serialization conflicts:
Because the new template is very flashy, want to use the data requests are used in the Web API, but when used, the returned JSON data, returned the < field name >k_backingfield, this silly, looked at the document, said in the attribute or field tag, Use Datacontactattribute and DataMemberAttribute, after trying, found still not.
Later through Google, only to know that the original is the problem between SerializableAttribute and DataContractAttribute, back to the JSON data, It is serialized using SerializableAttribute, so we have to use the Web Api Json serialization when Application_Start is configured so that it is serialized only ( Only support Datacontact and DataMember).
protected voidApplication_Start () {arearegistration. Registerallareas (); Webapiconfig. Register (globalconfiguration. Configuration); Filterconfig. Registerglobalfilters (globalfilters. Filters); Routeconfig. RegisterRoutes (routetable. Routes); Bundleconfig. Registerbundles (bundletable. Bundles); //configuration in WEBPI, only support Datacontactvarserializersettings =globalconfiguration. Configuration.Formatters.JsonFormatter.SerializerSettings; varContractresolver = (Defaultcontractresolver) Serializersettings.contractresolver; Contractresolver.ignoreserializableattribute =true; }
Written in the last
Before always feel that with Baidu is enough, but now it seems that the technical query, or Google comparison to force, many of these problems are solved by Google. Recently because the VPN expires, so has not used Google, recently really can't hold back, bought a VPN, with good, the price is not expensive, we can use the following: Hard knock. can use 360 browser, automatic switch mode, very convenient. Method click to view.
Summary of problems encountered in recent development