Giter VIP home page Giter VIP logo

Comments (4)

MaceWindu avatar MaceWindu commented on June 12, 2024 1

That is correct behavior. Default schema tried last to allow user to override it using more specific schema.

from linq2db.

linmic30 avatar linmic30 commented on June 12, 2024

The problem only is the codes never gets to the default schema because of the following code in the MappingSchema class:

		/// Gets attributes of specified type, associated with specified type.
		/// </summary>
		/// <typeparam name="T">Mapping attribute type (must inherit <see cref="MappingAttribute"/>).</typeparam>
		/// <param name="type">Attributes owner type.</param>
		/// <returns>Attributes of specified type.</returns>
		private T[] GetAllAttributes<T>(Type type)
			where T : MappingAttribute
		{
			return Schemas[0].MetadataReader?.GetAttributes<T>(type) ?? Array<T>.Empty;
		}

		/// <summary>
		/// Gets attributes of specified type, associated with specified type member.
		/// </summary>
		/// <typeparam name="T">Mapping attribute type (must inherit <see cref="MappingAttribute"/>).</typeparam>
		/// <param name="type">Member's owner type.</param>
		/// <param name="memberInfo">Attributes owner member.</param>
		/// <returns>Attributes of specified type.</returns>
		private T[] GetAllAttributes<T>(Type type, MemberInfo memberInfo)
			where T : MappingAttribute
		{
			return Schemas[0].MetadataReader?.GetAttributes<T>(type, memberInfo) ?? Array<T>.Empty;
		}

With using Schema[0] it always takes the first of the list. What we see is that AddSqlServer on the DataOptions adds two extra schemas to the beginning of this list. Forcing the default schema to the last position of the schema list.

from linq2db.

MaceWindu avatar MaceWindu commented on June 12, 2024

Schemas[0].MetadataReader is not just first metadata reader actually, but instance of https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Metadata/MetadataReader.cs which aggregates access to all metadata readers in MappingSchema on schema creation or when you add additional provider to current schema. If you add provider to child schema after current schema created - it will not affect current schema:

var ms = new MappingSchema();
// ms use metadata providers from Default schema

ms.AddMetadataReader(provider1);
// ms now use provider1 and providers from Default schema
// with provider1 having higher priority

DefaultSchema.AddMetadataReader(provider2);
// default schema now have provider2 with highest priority alongside with other providers it already had
// but ms schema still works with provider1 and old set of providers, copied from default schema during
// ms schema creation

from linq2db.

linmic30 avatar linmic30 commented on June 12, 2024

Oke, I did mis the part that the default will be used when no more specific schema is defined. But, when the code that is in the original post is used, our own provider is not being called. The breakpoints in the getattributes are not being hit.

Imo this is because the default schema with our own provider is in the last place of the schema list. And with the code that is now in the library only the first schema will be used.

What is also a bit weird is that there will be two extra schema's without them being created knowingly.

from linq2db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.