Asp.net用于测试的db的本地副本(.mdf?)

时间:2017-01-20 06:45:38

标签: asp.net database entity-framework

没有背景故事:

  1. 我在服务器上有一个数据库,但我有一个创建此数据库的脚本

  2. 我在Microsoft SQL Server Management Studio中执行了此脚本,我现在可以在我的计算机上将其用作本地数据库。

  3. 我想测试我的StorageContext默认使用StorageContext中的web.config

    public StorageContext(string name = "name=StorageContext") : base(name) { }
    
  4. 我认为可能会将该数据库的本地副本作为*.mdf文件。然后添加连接字符串,在创建StorageContext时,只需使用TestDatabase作为参数。

    但是我得到了这个例外:

      

    EntityFramework.dll中出现“System.TypeInitializationException”类型的异常,但未在用户代码中处理

         

    输入初始化程序...'System.Data.Entity.Internal.AppConfig'

1 个答案:

答案 0 :(得分:1)

我认为如果你删除附加的数据库文件名并使用这样的东西,你的问题就会解决。

连接字符串可能如下所示:

public class OnSwipeTouchListener implements View.OnTouchListener {

    private GestureDetector gestureDetector;

    protected OnSwipeTouchListener(Context c) {
        gestureDetector = new GestureDetector(c, new GestureListener());
    }

    public boolean onTouch(final View view, final MotionEvent motionEvent) {
        return gestureDetector.onTouchEvent(motionEvent);
    }

    private final class GestureListener extends GestureDetector.SimpleOnGestureListener {

        private static final int SWIPE_THRESHOLD = 100;
        private static final int SWIPE_VELOCITY_THRESHOLD = 100;

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            try {
                float diffY = e2.getY() - e1.getY();
                float diffX = e2.getX() - e1.getX();
                if (Math.abs(diffX) > Math.abs(diffY)) {
                    if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffX > 0) {
                            onSwipeRight();
                        } else {
                            onSwipeLeft();
                        }
                    }
                } else {
                    if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                        if (diffY > 0) {
                            onSwipeDown();
                        } else {
                            onSwipeUp();
                        }
                    }
                }
            } catch (Exception exception) {
                exception.printStackTrace();
            }
            return false;
        }
    }

    public void onSwipeRight() {
    }

    public void onSwipeLeft() {
    }

    public void onSwipeUp() {
    }

    public void onSwipeDown() {
    }
}
相关问题