I want to use two different data sources in my Azure project:
我想在Azure项目中使用两个不同的数据源:
- a SQL Server that contains basic partial info regarding an item (allows indexable data and spatial search)
- 包含有关项目的基本部分信息的SQL Server(允许可索引数据和空间搜索)
- a Windows Azure Storage that contains full remaining info regarding an item (retrieved by key)
- 包含有关项目的完整剩余信息的Windows Azure存储(按键检索)
In this way I can combine the powerful of SQL Server with the easy scalability of Windows Azure Storage.
通过这种方式,我可以将强大的SQL Server与Windows Azure存储的轻松可扩展性相结合。
Imagine this Domain POCO class:
想象一下这个域POCO类:
class Person
{
string Id { get; set; }
string Name { get; set; }
byte[] Picture { get; set; }
string Biography { get; set; }
}
I would like to use Entity Framework with fluent mapping to let EF understand that the properties Picture and Biography must be loaded from Windows Azure Storage (table, blob) instead of SQL Server (possibly Lazy loaded).
我想使用具有流畅映射的Entity Framework让EF了解必须从Windows Azure存储(table,blob)而不是SQL Server(可能是Lazy加载)加载属性Picture和Biography。
There's a way with EF (or NHibernate) to do this or I have to implement my own ORM strategy?
EF(或NHibernate)有办法实现这一目标,还是我必须实施自己的ORM策略?
Thanks
谢谢
2 个解决方案
#1
6
I don't think you can let EF know about Azure storage but you can map only necessary properties to a specific table. For example,
我认为您不能让EF了解Azure存储,但您只能将必要的属性映射到特定的表。例如,
modelBuilder.Entity<Person>().Ignore(p => p.Picture);
So assuming that you have a repository class for your Person class, what you want can be easily achieved by filling the repository class with Azure storage API and EF.
因此,假设您有Person类的存储库类,可以通过使用Azure存储API和EF填充存储库类来轻松实现所需的内容。
#2
6
You're trying to solve this problem too early (at the DAL) in my opinion. Look at the web, it fetches large data (e.g. pictures) in a separate call to the server. That has scaled very well. The picture data is not included in the document itself for a reason, it would just slow everything down and it would not be very fault tolerant. If you put them together in one entity you've got the fast entity retrieval that is slowed down by your picture server as they both have to come together before leaving towards your business layer and finally towards the presentation layer. And in the business layer this data is probably just wasting memory (that's why you want to lazy load it). So I think you're making the decision too early. What you describe as your domain object looks like a domain object of the presentation layer to me, similar to a ViewModel. I'm not too big into domain driven design, but while there is a general model of your application, I assume that each part of your application will require a slightly different implementation of that model.
在我看来,你过早地(在DAL)试图解决这个问题。查看网络,它在对服务器的单独调用中获取大数据(例如图片)。这已经很好地扩展了。由于某种原因,图片数据不包含在文档本身中,它只会减慢一切,并且不会具有容错能力。如果你将它们放在一个实体中,你就会得到快速的实体检索,它会被你的图片服务器放慢速度,因为它们必须在离开你的业务层然后最终走向表示层之前聚集在一起。在业务层中,这些数据可能只是在浪费内存(这就是你想要延迟加载它的原因)。所以我认为你太早做出决定。您描述为域对象的内容对我来说就像是表示层的域对象,类似于ViewModel。我对域驱动设计并不是太大,但是虽然有一个应用程序的通用模型,但我认为应用程序的每个部分都需要稍微不同的模型实现。
Regarding lazy loading, if you have that enabled and you attempt to send your object over the wire, even if Picture was not loaded, it will get serialized since the data contract serializer (or any other) will call get on your property.
关于延迟加载,如果你已启用并且尝试通过网络发送对象,即使未加载图片,它也会被序列化,因为数据合同序列化程序(或任何其他)将调用您的属性上的get。
That's probably not the answer you wanted, but I felt that I had to say this. Of course I am open to comments and criticism.
这可能不是你想要的答案,但我觉得我不得不说这个。当然,我愿意接受评论和批评。
#1
6
I don't think you can let EF know about Azure storage but you can map only necessary properties to a specific table. For example,
我认为您不能让EF了解Azure存储,但您只能将必要的属性映射到特定的表。例如,
modelBuilder.Entity<Person>().Ignore(p => p.Picture);
So assuming that you have a repository class for your Person class, what you want can be easily achieved by filling the repository class with Azure storage API and EF.
因此,假设您有Person类的存储库类,可以通过使用Azure存储API和EF填充存储库类来轻松实现所需的内容。
#2
6
You're trying to solve this problem too early (at the DAL) in my opinion. Look at the web, it fetches large data (e.g. pictures) in a separate call to the server. That has scaled very well. The picture data is not included in the document itself for a reason, it would just slow everything down and it would not be very fault tolerant. If you put them together in one entity you've got the fast entity retrieval that is slowed down by your picture server as they both have to come together before leaving towards your business layer and finally towards the presentation layer. And in the business layer this data is probably just wasting memory (that's why you want to lazy load it). So I think you're making the decision too early. What you describe as your domain object looks like a domain object of the presentation layer to me, similar to a ViewModel. I'm not too big into domain driven design, but while there is a general model of your application, I assume that each part of your application will require a slightly different implementation of that model.
在我看来,你过早地(在DAL)试图解决这个问题。查看网络,它在对服务器的单独调用中获取大数据(例如图片)。这已经很好地扩展了。由于某种原因,图片数据不包含在文档本身中,它只会减慢一切,并且不会具有容错能力。如果你将它们放在一个实体中,你就会得到快速的实体检索,它会被你的图片服务器放慢速度,因为它们必须在离开你的业务层然后最终走向表示层之前聚集在一起。在业务层中,这些数据可能只是在浪费内存(这就是你想要延迟加载它的原因)。所以我认为你太早做出决定。您描述为域对象的内容对我来说就像是表示层的域对象,类似于ViewModel。我对域驱动设计并不是太大,但是虽然有一个应用程序的通用模型,但我认为应用程序的每个部分都需要稍微不同的模型实现。
Regarding lazy loading, if you have that enabled and you attempt to send your object over the wire, even if Picture was not loaded, it will get serialized since the data contract serializer (or any other) will call get on your property.
关于延迟加载,如果你已启用并且尝试通过网络发送对象,即使未加载图片,它也会被序列化,因为数据合同序列化程序(或任何其他)将调用您的属性上的get。
That's probably not the answer you wanted, but I felt that I had to say this. Of course I am open to comments and criticism.
这可能不是你想要的答案,但我觉得我不得不说这个。当然,我愿意接受评论和批评。