我的db位置在哪里? [英] Where is my db location?

查看:160
本文介绍了我的db位置在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实体框架6.

我使用代码在Visual Studio 2013中创建数据库,但物理位置在哪里?我看不到它。

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel.DataAnnotations;
使用 System.Data.Entity;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;

命名空间 _3_2
{
class 计划
{
静态 void Main( string [] args)
{
使用(ShopContext ctx = new ShopContext())
{
地址a = new 地址
{
AddressLine1 = 某处1
AddressLine2 = < span class =code-string>在某个楼层,
City = SomeCity
ZipCode = 1111 AA
};
客户c = new 客户()
{
FirstName = John
LastName = Doe
BillingAddress = a,
ShippingAddress = a
};
ctx.Customers.Add(c);
ctx.SaveChanges();
}
}
}

public class ShopContext:DbContext
{
public IDbSet< Customer>客户{获取; set ; }
受保护 覆盖 void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity< Customer>()。HasRequired(bm = > bm.BillingAddress)
.WithMany()。WillCascadeOnDelete( false );
}
}

public class 客户
{
public int ID {获得; set ; }

[必需,MaxLength( 20 )]
public string FirstName { get ; set ; }

[必需,MaxLength( 20 )]
public string LastName { get ; set ; }

[必需]
public 地址ShippingAddress { get ; set ; }

[必填]
public 地址BillingAddress { get ; set ; }
}

public class 地址
{
public int ID { get ; set ; }

[必需,MaxLength( 20 )]
public string AddressLine1 { get ; set ; }

[必需,MaxLength( 20 )]
public string AddressLine2 { get ; set ; }

[必需,MaxLength( 20 )]
public 字符串城市{获取; set ; }

[RegularExpression( @ ^ [1-9] [0-9] { 3} \??[a-zA-Z] {2} $)]
public string ZipCode { get ; set ; }
}
}

解决方案

)]
public string ZipCode { get ; set ;}
}
}


最后,

< pre lang =c#> public class ShopContext:DbContext
{

public ShopContext()
base name = ShopDBConnectionString
{
}





< connectionstrings> 
< add name = ShopDBConnectionString >
connectionString = 数据源=。;初始目录= ShopDBConnectionString; Integrated Security = true
providerName = System.Data.SqlClient />
< / add > < / connectionstrings >



使用表示在VS 2013中的sql server explorer中添加连接时的sql server名称..


在哪里将取决于许多因素,主要是您正在使用的数据库系统。

如果您使用的是SQL Server,那么它是相对的简单。

以通常的方式通过SSMS登录,右键单击对象资源管理器窗格中的正确服务器。

从上下文菜单中选择属性,然后选择数据库设置 从显示的对话框的选择页面面板。

底部附近是数据库默认位置 - 您的数据库将位于数据文件夹中。

Entity Framework 6.
I use the code to create a database in Visual Studio 2013, but where is the physical location? I couldn't see it.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _3_2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ShopContext ctx = new ShopContext())
            {
                Address a = new Address
                {
                    AddressLine1 = "Somewhere 1",
                    AddressLine2 = "At some floor",
                    City = "SomeCity",
                    ZipCode = "1111AA"
                };
                Customer c = new Customer()
                {
                    FirstName = "John",
                    LastName = "Doe",
                    BillingAddress = a,
                    ShippingAddress = a
                };
                ctx.Customers.Add(c);
                ctx.SaveChanges();
            }
        }
    }

    public class ShopContext : DbContext
    {
        public IDbSet<Customer> Customers { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Customer>().HasRequired(bm => bm.BillingAddress)
                .WithMany().WillCascadeOnDelete(false);
        }
    }

    public class Customer
    {
        public int Id { get; set; }

        [Required, MaxLength(20)]
        public string FirstName { get; set; }

        [Required, MaxLength(20)]
        public string LastName { get; set; }

        [Required]
        public Address ShippingAddress { get; set; }

        [Required]
        public Address BillingAddress { get; set; }
    }

    public class Address
    {
        public int Id { get; set; }

        [Required, MaxLength(20)]
        public string AddressLine1 { get; set; }

        [Required, MaxLength(20)]
        public string AddressLine2 { get; set; }

        [Required, MaxLength(20)]
        public string City { get; set; }

        [RegularExpression(@"^[1-9][0-9]{3}\s?[a-zA-Z]{2}$")]
        public string ZipCode { get; set; }
    }
}

解决方案

")] public string ZipCode { get; set; } } }


Finally,

public class ShopContext : DbContext
   {

       public ShopContext()
           : base("name=ShopDBConnectionString")
           {
           }


and

<connectionstrings>
     <add name="ShopDBConnectionString">
     connectionString="Data Source=.;Initial Catalog=ShopDBConnectionString;Integrated Security=true"
     providerName="System.Data.SqlClient"/>
   </add></connectionstrings>


Use . to represent the sql server name while add connection in sql server explorer in VS 2013..


Where is is will depend on a number of factors, primarily which database system you are using.
If you are using SQL Server, then it's relatively easy.
Log in via SSMS in the usual way, and right click the correct server in the Object Explorer pane.
Select "Properties" from the context menu, then "Database Settings" from the "Select a page" panel of the dialog that appears.
Near the bottom is the "Database default locations" - your DB will be in the Data folder.


这篇关于我的db位置在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆