如何使用我的数据库,以SQL成员资格提供程序和实体框架的工作? [英] How to make sql membership provider and entity framework work using my database?

查看:174
本文介绍了如何使用我的数据库,以SQL成员资格提供程序和实体框架的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有.NET MVC 3项目中,我使用SQL成员资格提供程序和实体框架。

我已经在我的SQL服务器上创建新的数据库,并使用创造了成员资格提供的所有对象 aspnet_regsql.exe的,我已经改变了我的连接字符串,它工作正常。

现在我想使用实体框架分贝互动。我使用code-首先所以我创建简单的实体类,我可以将数据保存到数据库从其获取它。

问题是,当实体框架,保持它的数据的地方是一个谜。我找不到我的项目中的任何数据库,并有我的SQL数据库中没有新表。

如果我添加第二个连接字符串的web.config(第一个是为成员提供)我的实体框架停止工作(我假定它应该创建在我的数据库的新表),但它并没有做到这一点。

我的实体类是这样的:

 公共类MyEntities:{的DbContext
    公共DbSet<商业与GT;企业{搞定;组; }
}

和我得到一个异常无效的对象名称dbo.Businesses

任何帮助将大大AP preciated。

我的连接字符串是这样的:

 <添加名称=ApplicationServices
   的connectionString =数据源=;
                     初始目录= MyDbName;
                     持续安全信息= TRUE;
                     用户ID = SA;
                     密码=输入mypassword
   的providerName =System.Data.SqlClient的
/>
<添加名称=MyEntities
     的connectionString =数据源=;
                      初始目录= MyDbName;
                      持续安全信息= TRUE;
                      用户ID = SA;
                      密码=输入mypassword
     的providerName =System.Data.SqlClient的
 />


解决方案

HTTP://www.$c$cproject.com/KB/web-security/EFMembershipProvider.aspx 这是实现实体框架custome成员提供很好的例子。并首先阅读本
<一href=\"http://stackoverflow.com/questions/620350/can-i-use-entity-framework-with-asp-net-membership\">Can我使用实体框架与ASP.NET会员?

I have .NET MVC 3 project where I use sql membership provider and entity framework.

I've created new database on my SQL server and created all objects for membership provider using aspnet_regsql.exe, I've changed my connection string and it works fine.

Now I want to use entity framework for db interaction. I'm using Code-First so I created simple entity class and I can save data to db and retreive it.

The problem is that the place where entity framework keeps it's data is a mistery. I can not find any database in my project and there are no new tables in my SQL database.

If I add second connection string to web.config (the first one is for membership provider) my entity framework stops working (I assume it should create new tables in my DB) but it does not do it.

My entity class looks like:

public class MyEntities : DbContext {
    public DbSet<Business> Businesses { get; set; }
}

And I'm getting an exception Invalid object name 'dbo.Businesses'

Any help will be greatly appreciated.

my connection strings look like this:

<add name="ApplicationServices"
   connectionString="Data Source=.;  
                     Initial Catalog=MyDbName;  
                     Persist Security Info=True;  
                     User ID=sa;  
                     Password=mypassword"
   providerName="System.Data.SqlClient"
/>
<add name="MyEntities"
     connectionString="data source=.;
                      Initial Catalog=MyDbName;
                      Persist Security Info=True;
                      User ID=sa;
                      Password=mypassword"
     providerName="System.Data.SqlClient" 
 />

解决方案

http://www.codeproject.com/KB/web-security/EFMembershipProvider.aspx this is good example which implements custome membership provider with entity framework. And read this first Can I use Entity Framework with ASP.NET Membership?

这篇关于如何使用我的数据库,以SQL成员资格提供程序和实体框架的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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