C# 当我已经有了模型和数据库时,我可以使用实体框架吗?
在我的工作WPF应用程序中,我已经有了我的模型和sqlce数据库。 但是现在我使用普通的参数化查询来检索、更新或删除数据 我是否仍然可以使用实体框架进行此操作,还是已经太晚了?我的模型实现了INotifyChangedProperty(MVVM应用程序) 现在是我的AddressModel中插入方法的一个示例。我想用实体框架来改变这一点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
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);
}
}
谢谢 是的,你可以
实体框架有三个工作流:数据库优先
、模型优先
和代码优先
,因此在这三个工作流中,您可以使用数据库优先
EF
。我将在周末查看。。看看我是否理解你的答案正确,EF将创建新模型,我可以更改InotifyProperty的属性?