由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - Entity Framework Open Sourced
相关主题
有用过spring.net 和 Nhibernate的大牛吗?[合集] 谈谈我的.NET
Linq to entity framework: what happens if i modified DB schema in SSMS ?entity framework 4.1 code first Invalid column name error
Entity Framework Today?DataTable.NewRow的primary key初始为0的问题
some1 using nhibernate?请问大家,目前.NET业界(美国)用的最多的技术是什么?
[合集] some1 using nhibernate?菜人问问,你们都在database上干什么??
LINQ vs nHibernate大家的网页url现在还是.....aspx,还是用新的mvc4做的只看见path: .../person/add ?
Entity frameworkLINQ to SQL VS Entity Framework
再问大家,关于.netWho can tell me why i cannot connect to the SQL db file ?
相关话题的讨论汇总
话题: entities话题: open话题: entity话题: user话题: sourced
进入DotNet版参与讨论
1 (共1页)
s***o
发帖数: 2191
1
http://weblogs.asp.net/scottgu/archive/2012/07/19/entity-framew
So there are two different versions of Microsoft - DevDiv is more and more
open while WinDiv is more and more closed
o****e
发帖数: 916
2
正好问个EF的问题
user table有个ID field
product table 有个 UserID field, 是user id的foreign key
现在有个database的entities object,比如 _entities
User user = _entities.Users.First(u=>u.ID == 1)
list user.Products
这时有另外一个连接对数据库操作,删除了user 1的一个product
但如果对原先的 _entities 再运行代码
user = _entities.Users.First(u=>u.ID == 1)
返回的user.Products collection还是原来的,删掉那个还在,试了refresh user
object也没有用。
求高手指点!谢谢!
k****i
发帖数: 1072
3
_entities.Entry(user).Collection(p => p.Products).CurrentValue.Clear();
_entities.Entry(user).Collection(p => p.Products).Load();

【在 o****e 的大作中提到】
: 正好问个EF的问题
: user table有个ID field
: product table 有个 UserID field, 是user id的foreign key
: 现在有个database的entities object,比如 _entities
: User user = _entities.Users.First(u=>u.ID == 1)
: list user.Products
: 这时有另外一个连接对数据库操作,删除了user 1的一个product
: 但如果对原先的 _entities 再运行代码
: user = _entities.Users.First(u=>u.ID == 1)
: 返回的user.Products collection还是原来的,删掉那个还在,试了refresh user

c**d
发帖数: 579
4
这个写法很容易出这种奇怪的错。如果需要用到child objects的话,直接eager
loading,
_entities.Include(u => u.Products).First(u => u.ID == 1)
o****e
发帖数: 916
5
多谢回复,Entry extension 在EF 4.1才支持,我还在用4.0,没能试一下

【在 k****i 的大作中提到】
: _entities.Entry(user).Collection(p => p.Products).CurrentValue.Clear();
: _entities.Entry(user).Collection(p => p.Products).Load();

o****e
发帖数: 916
6
多谢回复,刚试了一下,一样的结果,删掉的product还在...

【在 c**d 的大作中提到】
: 这个写法很容易出这种奇怪的错。如果需要用到child objects的话,直接eager
: loading,
: _entities.Include(u => u.Products).First(u => u.ID == 1)

S***k
发帖数: 370
7
the instance _entities holds the initial info loaded from the database.
a new instance of the database entity is needed to get the latest records in
database.

【在 o****e 的大作中提到】
: 正好问个EF的问题
: user table有个ID field
: product table 有个 UserID field, 是user id的foreign key
: 现在有个database的entities object,比如 _entities
: User user = _entities.Users.First(u=>u.ID == 1)
: list user.Products
: 这时有另外一个连接对数据库操作,删除了user 1的一个product
: 但如果对原先的 _entities 再运行代码
: user = _entities.Users.First(u=>u.ID == 1)
: 返回的user.Products collection还是原来的,删掉那个还在,试了refresh user

s***o
发帖数: 2191
8
What about calling "Refresh" at "Product" level?
context.Refresh(RefreshMode.StoreWins, yourProductCollection);
btw, it sounds like you are using a long-lasting global context instance?

【在 o****e 的大作中提到】
: 正好问个EF的问题
: user table有个ID field
: product table 有个 UserID field, 是user id的foreign key
: 现在有个database的entities object,比如 _entities
: User user = _entities.Users.First(u=>u.ID == 1)
: list user.Products
: 这时有另外一个连接对数据库操作,删除了user 1的一个product
: 但如果对原先的 _entities 再运行代码
: user = _entities.Users.First(u=>u.ID == 1)
: 返回的user.Products collection还是原来的,删掉那个还在,试了refresh user

o****e
发帖数: 916
9
yes, I used a singleton to access database, context is a static in that
class. I took this approach to avoid overhead of creating db connection
every time a query is made, as the web server and database are in different
machines. I will try out the refresh on collection.

【在 s***o 的大作中提到】
: What about calling "Refresh" at "Product" level?
: context.Refresh(RefreshMode.StoreWins, yourProductCollection);
: btw, it sounds like you are using a long-lasting global context instance?

S***k
发帖数: 370
10
This could help:
http://stackoverflow.com/questions/3653009/entity-framework-and
Creating a context does not cost too much. If your application is web based
and accessed by multiple users, creating a new context for each request and
disposing the context instance by "using" could help to reduce the DB load
caused by the refreshing.

different

【在 o****e 的大作中提到】
: yes, I used a singleton to access database, context is a static in that
: class. I took this approach to avoid overhead of creating db connection
: every time a query is made, as the web server and database are in different
: machines. I will try out the refresh on collection.

1 (共1页)
进入DotNet版参与讨论
相关主题
Who can tell me why i cannot connect to the SQL db file ?[合集] some1 using nhibernate?
求网络项目 (转载)LINQ vs nHibernate
vs2015: ADO.NET Entity Data Model Designer没了Entity framework
[合集] help: 又没有现成的.NET 网站的source code? (转载)再问大家,关于.net
有用过spring.net 和 Nhibernate的大牛吗?[合集] 谈谈我的.NET
Linq to entity framework: what happens if i modified DB schema in SSMS ?entity framework 4.1 code first Invalid column name error
Entity Framework Today?DataTable.NewRow的primary key初始为0的问题
some1 using nhibernate?请问大家,目前.NET业界(美国)用的最多的技术是什么?
相关话题的讨论汇总
话题: entities话题: open话题: entity话题: user话题: sourced