Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当我已经有了模型和数据库时,我可以使用实体框架吗?_C#_.net_Wpf_Entity Framework 5 - Fatal编程技术网

C# 当我已经有了模型和数据库时,我可以使用实体框架吗?

C# 当我已经有了模型和数据库时,我可以使用实体框架吗?,c#,.net,wpf,entity-framework-5,C#,.net,Wpf,Entity Framework 5,在我的工作WPF应用程序中,我已经有了我的模型和sqlce数据库。 但是现在我使用普通的参数化查询来检索、更新或删除数据 我是否仍然可以使用实体框架进行此操作,还是已经太晚了?我的模型实现了INotifyChangedProperty(MVVM应用程序) 现在是我的AddressModel中插入方法的一个示例。我想用实体框架来改变这一点 public int InsertNewAddress(bool isnew) { IsNew = isnew; try { Arr

在我的工作WPF应用程序中,我已经有了我的模型和sqlce数据库。 但是现在我使用普通的参数化查询来检索、更新或删除数据

我是否仍然可以使用实体框架进行此操作,还是已经太晚了?我的模型实现了INotifyChangedProperty(MVVM应用程序)

现在是我的AddressModel中插入方法的一个示例。我想用实体框架来改变这一点

    public int InsertNewAddress(bool isnew)
{
  IsNew = isnew;
  try
  {
    ArrayList paramList = new ArrayList();
    paramList.Add(new SqlCeParameter() { ParameterName = "@Id", Value = Id, DbType = DbType.Guid, Size = 16, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Street", Value = Street, DbType = DbType.String, Size = 50, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Number", Value = Number, DbType = DbType.String, Size = 10, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Bus", Value = DBNull.Value, DbType = DbType.String, Size = 5, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@ZipCode", Value = Zipcode, DbType = DbType.String, Size = 10, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@City", Value = City, DbType = DbType.String, Size = 50, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Created", Value = DateTime.Now, DbType = DbType.DateTime, Size = 23, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Modified", Value = DateTime.Now, DbType = DbType.DateTime, Size = 23, Direction = ParameterDirection.Input });
    paramList.Add(new SqlCeParameter() { ParameterName = "@Country", Value = Country, DbType = DbType.String, Size = 50, Direction = ParameterDirection.Input });

    StringBuilder sb = new StringBuilder();

    if (IsNew) // new address, insert
    {
      sb.Append("INSERT INTO [RF_Address] ");
      sb.Append("([Id],[Street],[Number],[Bus],[ZipCode],[City] ,[DateCreated],[DateModified], [Country]) ");
      sb.Append("VALUES ");
      sb.Append("(@Id, @Street, @Number, @Bus, @ZipCode, @City, @Created, @Modified, @Country)");
    }
    else
    {
      sb.Append("UPDATE  [RF_Address] ");
      sb.Append("SET ");
      sb.Append("[Street] = @Street, [Number] = @Number, [Bus] = @Bus, [ZipCode] = @ZipCode, [City] = @City, ");
      sb.Append("[DateModified] = @Modified,  [Country] = @Country ");
      sb.Append("WHERE [Id] = @Id");
    }

    int result = SqlCeHelper.ExecuteNonQuery(sb.ToString(), paramList);
    if (result != 1)
      throw new CustomException("Insert address failed!");

    return result;
  }
  catch (CustomException appEx)
  {
    throw new CustomException(appEx.Message, appEx);
  }
  catch (Exception ex)
  {
    throw new Exception("Error InsertNewAddress: " + ex.Message, ex);
  }
}
谢谢

是的,你可以

实体框架有三个工作流:
数据库优先
模型优先
代码优先
,因此在这三个工作流中,您可以使用
数据库优先


Thx用于快速回复。如果我理解正确,这将创建新的模型?我的应用程序是WPF MVVM应用程序,因此我的模型实现了INotifyPropertyChanged。我可以将实体框架生成的模型移植到吗?是的,您将被迫迁移代码,因为您想使用
EF
。我将在周末查看。。看看我是否理解你的答案正确,EF将创建新模型,我可以更改InotifyProperty的属性?