I would like to use Do.net to map an existing database. We would use this for a simple mapping in read only mode.

Is there a sample or a documentation for this?

We would use a different schema for those tables, in the same database than our normal DO.Net domain : is it possible to use LINQ to query objects from the two domains in the same query?

asked Nov 30 '10 at 10:07

olorin's gravatar image

olorin
358878792


One Answer:

DO can be used to map entities to existing database - there are two special upgrade modes for this:

  • DomainUpgradeMode.LegacySkip - skip any schema checks
  • DomainUpgradeMode.LegacyValidate - ensure all mapped structures (tables and columns) are available @ DB; fail, if something isn't there.

Since DO doesn't use Metadata.* tables in legacy modes, you must explicitly sppecify type discriminator field and value for each type using [TypeDiscriminator] and [TypeDiscriminatorValue(...)] attributes.

Currently legacy mode has a set of limitations:

  • IDENTITY columns are not supported -you must use generators or write your own ones. This should be done in near future, see issue 415.
  • Mappings to multiple schemes aren't supported. Also planned, see issue 576.
  • Mappings to views and stored procedures are not supported, although this is frequently necessary in this mode. Nothing is planned here yet.
  • T4-based model code generation (ActiveRecord pattern) isn't available, i.e. you should write the classes by your own. Planned, see [issue 721].
  • If you're going to use non-paired EntitySets, you can't define table and column mappings for runtime-generated type we use to represent its items. Usage of such non-paired EntitySets is optional, but this is pretty convenient to use them in many cases. See issue 250.
  • Also, you can't fully control mappings for composite foreign keys. See issue 780.

AFAIK, this is the full list of limitations.

So exact answers to your questions are:

Is there a sample or a documentation for this?

Unfortunately, no, although rules here are pretty simple:

  • Use DomainUpgradeMode.LegacySkip or DomainUpgradeMode.LegacyValidate to turn this feature on.
  • If mapped table and column names names differ from derived by default mapping rules, use [TableMapping] and [FieldMapping] attributes.
  • You must explicitly specify type discriminators (using [TypeDiscriminator] and [TypeDiscriminatorValue(...)] attributes), if you're going to map inheritance hierarchies. Note that inheritance hierarchies can also be represented as non-inherited types containing reference as key of "descendant" type.
  • Take all specified limitations into account.

We'll add this to Manual shipped with v4.4.

We would use a different schema for those tables, in the same database than our normal DO.Net domain...

If there is a single schema, you'll be able to map the entities in separate Domain. But if there are multiple ones, you won't be able to do this.

Is it possible to use LINQ to query objects from the two domains in the same query?

No, LINQ queries can reference only entities from a single Domain.

And finally, recommendations:

  • Use LINQ to SQL to query the legacy part of data, if this is possible - it is a perfect tool for such tasks. You can try to even query the whole database - L2S contexts can be populated from generally any schema, so at least you'll be able to query all the data.
  • Another alternative is to use plain SQL instead of L2S, if this option is acceptable. If this is necessary for reporting, likely, this is the only good option (AFAIK, reporting engines are still mainly SQL-based).

answered Dec 01 '10 at 10:28

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Thank you for this complete answer. I'll test this. As you said, it might simpler to use Linq2Sql, because we are in read only mode with only one table...

(Dec 03 '10 at 10:28) olorin olorin's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA