当前位置: 首页 > news >正文

温州网站制作多少钱泰安新闻完整版

温州网站制作多少钱,泰安新闻完整版,重庆企业网站推广,免费app下载负二、配置说明 最近想做个东西#xff0c;用到了SQLite#xff0c;按照之前的方法步骤搭建的结果失败了#xff0c;因为SQLite的版本升级了#xff0c;导致Migration自动迁移各种报错#xff0c;而且我查了一下自动迁移的包貌是不再更新了。——2018年1月24日 能正常使用…负二、配置说明 最近想做个东西用到了SQLite按照之前的方法步骤搭建的结果失败了因为SQLite的版本升级了导致Migration自动迁移各种报错而且我查了一下自动迁移的包貌是不再更新了。——2018年1月24日 能正常使用的配置清单如下不要升级包升级包会导致一系列的坑 EF 6.1.3 SQLite.CodeFirst 1.3.1.18 System.Data.SQLite 1.0.105.2 System.Data.SQLite.Core 1.0.105.2 System.Data.SQLite.EF6 1.0.105.2 System.Data.SQLite.EF6.Migrations 1.0.104 System.Data.SQLite.Linq 1.0.105.2 文章最底下可以下载源码能正常使用但是SQLite升级到了1.0.106之后就不能再使用原来的System.Data.SQLite.EF6.Migrations了。 负一、吐个槽 关于SQLite的CodeFirst我找了很久有很多博客都写过但是真正好用的非常少还有很多根本就是DBFirst的代码真是坑的我够呛研究了几天也算有点成果整理一下希望对路过的朋友有所帮助。 零、冷知识 1、SQLite.CodeFirst 使用NuGet安装的EF和SQLite可能是没有CodeFirst功能的安装了“SQLite.CodeFirst”之后可以为SQLite提供CodeFirst的功能。 2、System.Data.SQLite.EF6.Migrations 数据库迁移 SQLite 是没有数据库迁移 MigrationSqlGenerator 功能的 我所查询的资料是这样的有错请指正非常感谢甚至有人说得自己写一个数据迁移的功能那是不是有点辛苦。 还好在 NuGet 上有一个“System.Data.SQLite.EF6.Migrations”详细内容可以访问他的网站网站上有说明文档安装之后可以做简单的数据库修改可以添加表中的列但是并不能删除和修改列因为 SQLite 并不认识 drop column 和 rename column至于为什么不认识看下条。 3、SQLite不支持的语法 关于这个可以自己百度查一下 ^ _ ^ ~ 4、关于SQLite中的数据关系 我在试验的过程中发现SQLite的数据关系并不可靠尤其是EF的子查询我就没有尝试成功还有使用外键的时候也并不正常。 5、SQLite 中的 Guid 在 SQLite 中使用 Guid 的时候因为 SQLite 中 Guid 会使用 BLOB 类型来存储就是二进制所以用 Linq 直接 Idid 是查不到东西的使用 tostring 也得不到正确的格式建议在使用 EF SQLite 的时候使用 string 来存储 Guid 数据。 使用 SQLite 读取工具打开数据库文件就会发现 Guid 是 BLOB 存储的并且顺序和 C# 生成的 Guid 并不相同。如果非要使用 Guid 可以研究一下 Guid 和二进制的转换。 一、安装过程 OK 进入正题 使用NuGet安装时相关联的都会自动下载所以这点还是很方便的这里列一下安装完之后都有啥 EntityFrameworkEntityFramework.zh-Hans中文说明SQLite.CodeFirst实现CodeFirstSystem.Data.SQLiteSystem.Data.SQLite.CoreSystem.Data.SQLite.EF6System.Data.SQLite.EF6.Migrations提供数据库迁移System.Data.SQLite.Linq 安装过程就这样…… 二、简单配置一下 虽然安装的时候会自动写入一些配置信息但是还是可能有些遗漏查漏补缺一下 App.config 文件 entityFramework-providers 下检查添加 provider invariantNameSystem.Data.SQLite typeSystem.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 /connectionStrings 下检查添加 add nameDefaultConnection connectionStringdata sourcesqliter.db providerNameSystem.Data.SQLite /三、数据库工具类 一个简单例子只需要4个类 Entity 类实体类Mapping 类实体配置DbContext 类数据库操作Configuration 类设置信息 首先来一个简单“栗子” Entity 类 public class Bus {public string Id { get; set; }public string Name { get; set; } } public class Person {public string Id { get; set; }public string Name { get; set; } }Mapping 类 public class Mapping {public class BusMap : EntityTypeConfigurationBus{public BusMap(){}}public class PersonMap : EntityTypeConfigurationPerson{public PersonMap(){}} }DBContext 类 public class SQLiteDb : DbContext {public SQLiteDb() : base(DefaultConnection){Database.SetInitializer(new MigrateDatabaseToLatestVersionSQLiteDb, Configuration());}protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Conventions.RemovePluralizingTableNameConvention();modelBuilder.Configurations.AddFromAssembly(typeof(SQLiteDb).Assembly);} }Configuration 类: public class Configuration : DbMigrationsConfigurationSQLiteDb {public Configuration(){AutomaticMigrationsEnabled true;AutomaticMigrationDataLossAllowed true;SetSqlGenerator(System.Data.SQLite, new SQLiteMigrationSqlGenerator());}protected override void Seed(SQLiteDb context){// This method will be called after migrating to the latest version.// You can use the DbSetT.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g.//// context.People.AddOrUpdate(// p p.FullName,// new Person { FullName Andrew Peters },// new Person { FullName Brice Lambson },// new Person { FullName Rowan Miller }// );//} }四、操作代码 public partial class Form1 : Form {//创建BusBus Bus new Bus() { Id Guid.NewGuid().ToString(), Name 11 路 };public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){//默认往数据库添加一个Bususing (SQLiteDb db new SQLiteDb()){db.SetBus().Add(Bus);db.SaveChanges();}}//添加人员void InsertPerson(string name){using (SQLiteDb db new SQLiteDb()){Bus dbBus db.SetBus().Where(x x.Id Bus.Id).FirstOrDefault();db.SetPerson().Add(new Person() { Id Guid.NewGuid().ToString(), Name name, Bus dbBus });db.SaveChanges();}}//删除人员void DeletePerson(string id){using (SQLiteDb db new SQLiteDb()){Person p new Person() { Id id };Person person db.SetPerson().Attach(p);db.SetPerson().Remove(person);db.SaveChanges();}}//更新人员void UpdatePerson(string id, string name){using (SQLiteDb db new SQLiteDb()){Person p db.SetPerson().Where(x x.Id id).FirstOrDefault();p.Name name;db.SaveChanges();}}#region 点击按钮操作private void BtInsert_Click(object sender, EventArgs e){//清空文本框TbTxt.Text ;//插入人员InsertPerson(TbInsert.Text);//显示人员信息using (SQLiteDb db new SQLiteDb()){ListPerson persons db.SetPerson().ToList();if (persons ! null){persons.ForEach(x {TbTxt.Text x.Id x.Name Environment.NewLine;});}}}private void BtDelete_Click(object sender, EventArgs e){TbTxt.Text ;DeletePerson(TbDelete.Text);using (SQLiteDb db new SQLiteDb()){ListPerson persons db.SetPerson().ToList();if (persons ! null){persons.ForEach(x {TbTxt.Text x.Id x.Name Environment.NewLine;});}}}private void BtUpdate_Click(object sender, EventArgs e){TbTxt.Text ;UpdatePerson(TbUpdate.Text, DateTime.Now.ToString(mm:ss));using (SQLiteDb db new SQLiteDb()){ListPerson persons db.SetPerson().ToList();if (persons ! null){persons.ForEach(x {TbTxt.Text x.Id x.Name Environment.NewLine;});}}}private void BtSelect_Click(object sender, EventArgs e){TbTxt.Text ;if (TbSelect.Text ){//查询所有人员信息using (SQLiteDb db new SQLiteDb()){ListPerson persons db.SetPerson().ToList();if (persons ! null){persons.ForEach(x {TbTxt.Text x.Id x.Name Environment.NewLine;});}}}else{//根据Id查询人员using (SQLiteDb db new SQLiteDb()){Person person db.SetPerson().Where(x x.Id TbSelect.Text).FirstOrDefault();TbTxt.Text person.Id person.Name Environment.NewLine;}}}#endregion }长了点但一看就懂的。 五、异常处理 一、“System.InvalidOperationException”类型的未经处理的异常在 EntityFramework.dll 中发生 其他信息: No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SQLite’. Make sure the provider is registered in the ‘entityFramework’ section of the application config file. See http://go.microsoft.com/fwlink/?LinkId260882 for more information. 解决App.config中使用NuGet安装了SQLiteSQLite.Core,EF……之后默认的配置是这样的 providersprovider invariantNameSystem.Data.SqlClient typeSystem.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer /provider invariantNameSystem.Data.SQLite.EF6 typeSystem.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 / /providers而异常提示 provider with invariant name ‘System.Data.SQLite’所以只需要加上这行provider 配置就可以。 providersprovider invariantNameSystem.Data.SQLite typeSystem.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 / /providers二、“System.InvalidOperationException”类型的未经处理的异常在 EntityFramework.dll 中发生 其他信息: Unable to determine the principal end of an association between the types ‘SQLiter.TestEF.DbTool.IdCard’ and ‘SQLiter.TestEF.DbTool.Student’. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations. 解决在MVC中如果数据库表关系是一对一的需要加 [Required] 如 public class Employee {//员工必须有工牌[Required]public virtual ECard ECard { get; set; } }三、“System.Data.Entity.Validation.DbEntityValidationException”类型的未经处理的异常在 EntityFramework.dll 中发生 其他信息: Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details. 解决检查是否有字段是必须的。 注可以通过catch来获取更详细的提示 catch (DbEntityValidationException dbEx) {foreach (var validationErrors in dbEx.EntityValidationErrors){foreach (var validationError in validationErrors.ValidationErrors){Console.WriteLine(Class: {0}, Property: {1}, Error: {2},validationErrors.Entry.Entity.GetType().FullName,validationError.PropertyName,validationError.ErrorMessage);}} }代码下载 完整源码 如果没有积分也可以关注我获取哟~ 原来的公众号图被封了…_||| 如果有需要的话可以手动搜索公众号找一下【大鱼code】
http://wiki.neutronadmin.com/news/89666/

相关文章:

  • 上海做网站 公司瑞安做网站建设哪家好
  • 织梦cms零基础做网站搜狐做网站
  • 怎么制作网站店铺国土局网站建设情况
  • 企业网站在ps里做吗dw做的网站设计
  • 深圳做网站优化报价wordpress插件如何开发
  • 济南做网站企业在线工具网站
  • 北京网站开开发公司电话谷歌网站建站
  • 中山网站建设联系电话优秀网页设计导航
  • 新手学做网站书广科网站开发
  • 陕西省建设总工会网站即时通讯软件
  • 土地流转网站建设报告怎么查找一个网站开发时间
  • 怎样用网站做淘宝客推广wordpress 问答主题
  • 九江网站建设优化公司广州平面设计招聘
  • 建设银行软件官方网站下载网站关键词怎样做优化
  • cf刷枪网站怎么做的网站建设投资风险分析
  • 沈阳市绿云网站建设怎么在网上做装修网站
  • 郑州专业旅游网站建设百雀羚网站建设模版
  • 建筑网片铁丝规格新塘网站seo优化
  • 外贸网站建设电话做竞品分析去哪个网站
  • 北京网站设计制作招聘信息设计方案的步骤
  • 鞍山专业做网站公司淘宝网站建设目标是什么
  • 电脑网游网站seo排名
  • 罗湖商城网站设计推荐深圳网站维护seo
  • vip解析网站怎么做视频推广计划
  • 菏泽做网站设计星辰wordpress
  • 平谷重庆网站建设肥西县重点建设局网站
  • 投资网站排行佛山高端网站建设工作室
  • 大连好的网站建设公司更改wordpress登录图标
  • wordpress建站教程新手工作总结个人
  • 网站对联广告图片长沙一键建站系统