|
5493 | 5493 | if (c.IsMaxLength) |
5494 | 5494 | sb.Append(".IsMaxLength()"); |
5495 | 5495 |
|
5496 | | - if ((c.Precision > 0 || c.Scale > 0) && c.PropertyType == "decimal") |
| 5496 | + if ((c.Precision > 0 || c.Scale > 0) && DatabaseReader.IsPrecisionAndScaleType(c.SqlPropertyType)) |
5497 | 5497 | sb.AppendFormat(".HasPrecision({0},{1})", c.Precision, c.Scale); |
| 5498 | + else if (c.Precision > 0 && DatabaseReader.IsPrecisionType(c.SqlPropertyType) && c.SqlPropertyType != "float") |
| 5499 | + sb.AppendFormat(".HasPrecision({0})", c.Precision); |
5498 | 5500 |
|
5499 | 5501 | if (c.IsRowVersion) |
5500 | 5502 | sb.Append(".IsRowVersion()"); |
|
5766 | 5768 | columnTypeParameters = $"({c.MaxLength})"; |
5767 | 5769 |
|
5768 | 5770 | sb.AppendFormat(".HasColumnType(\"{0}{1}\")", c.SqlPropertyType, columnTypeParameters); |
| 5771 | + |
| 5772 | + if (Settings.IsEfCore5Plus()) |
| 5773 | + { |
| 5774 | + if ((c.Precision > 0 || c.Scale > 0) && DatabaseReader.IsPrecisionAndScaleType(c.SqlPropertyType)) |
| 5775 | + sb.AppendFormat(".HasPrecision({0},{1})", c.Precision, c.Scale); |
| 5776 | + else if (c.Precision > 0 && DatabaseReader.IsPrecisionType(c.SqlPropertyType)) |
| 5777 | + sb.AppendFormat(".HasPrecision({0})", c.Precision); |
| 5778 | + } |
5769 | 5779 | } |
5770 | 5780 |
|
5771 | 5781 | sb.Append(c.IsNullable ? ".IsRequired(false)" : ".IsRequired()"); |
|
5782 | 5792 | //if (c.IsMaxLength) |
5783 | 5793 | // sb.Append(".IsMaxLength()"); |
5784 | 5794 |
|
5785 | | - //if ((c.Precision > 0 || c.Scale > 0) && c.PropertyType == "decimal") |
5786 | | - // sb.AppendFormat(".HasPrecision({0},{1})", c.Precision, c.Scale); |
5787 | | - |
5788 | 5795 | if (c.IsRowVersion) |
5789 | 5796 | sb.Append(".IsRowVersion()"); |
5790 | 5797 |
|
|
6425 | 6432 | public interface IDatabaseToPropertyType |
6426 | 6433 | { |
6427 | 6434 | Dictionary<string, string> GetMapping(); // [Database type] = Language type |
| 6435 | + |
| 6436 | + /// <summary> |
| 6437 | + /// A list of the database types that are spatial. |
| 6438 | + /// </summary> |
6428 | 6439 | List<string> SpatialTypes(); |
| 6440 | + |
| 6441 | + /// <summary> |
| 6442 | + /// A list of the database types that contain precision. |
| 6443 | + /// </summary> |
| 6444 | + List<string> PrecisionTypes(); |
| 6445 | + |
| 6446 | + /// <summary> |
| 6447 | + /// A list of the database types that contain precision and scale. |
| 6448 | + /// </summary> |
| 6449 | + List<string> PrecisionAndScaleTypes(); |
6429 | 6450 | } |
6430 | 6451 | public interface IDatabaseLanguageFactory |
6431 | 6452 | { |
|
6582 | 6603 | "geography", "geometry", "point", "linestring", "polygon", "multipoint", "multilinestring", "multipolygon", "geometrycollection" |
6583 | 6604 | }; |
6584 | 6605 | } |
| 6606 | + |
| 6607 | + public List<string> PrecisionTypes() |
| 6608 | + { |
| 6609 | + return new List<string> { "float", "datetime", "time", "timestamp", "year" }; |
| 6610 | + } |
| 6611 | + |
| 6612 | + public List<string> PrecisionAndScaleTypes() |
| 6613 | + { |
| 6614 | + return new List<string> { "decimal", "numeric" }; |
| 6615 | + } |
6585 | 6616 | } |
6586 | 6617 |
|
6587 | 6618 | public class OracleToCSharp : IDatabaseToPropertyType |
|
6625 | 6656 | { |
6626 | 6657 | return new List<string> { "sdo_geometry" }; |
6627 | 6658 | } |
| 6659 | + |
| 6660 | + public List<string> PrecisionTypes() |
| 6661 | + { |
| 6662 | + return new List<string> { "float", "timestamp", "timestamp with time zone", "timestamp with local time zone" }; |
| 6663 | + } |
| 6664 | + |
| 6665 | + public List<string> PrecisionAndScaleTypes() |
| 6666 | + { |
| 6667 | + return new List<string> { "number" }; |
| 6668 | + } |
6628 | 6669 | } |
6629 | 6670 |
|
6630 | 6671 | public class PostgresToCSharp : IDatabaseToPropertyType |
|
6711 | 6752 | { |
6712 | 6753 | return new List<string> { "geometry", "point", "line", "lseg", "box", "path", "polygon", "circle" }; |
6713 | 6754 | } |
| 6755 | + |
| 6756 | + public List<string> PrecisionTypes() |
| 6757 | + { |
| 6758 | + return new List<string> { "float" }; |
| 6759 | + } |
| 6760 | + |
| 6761 | + public List<string> PrecisionAndScaleTypes() |
| 6762 | + { |
| 6763 | + return new List<string> { "decimal", "numeric" }; |
| 6764 | + } |
6714 | 6765 | } |
6715 | 6766 |
|
6716 | 6767 | public class SqlServerToCSharp : IDatabaseToPropertyType |
|
6758 | 6809 | { |
6759 | 6810 | return new List<string> { "geography", "geometry" }; |
6760 | 6811 | } |
| 6812 | + |
| 6813 | + public List<string> PrecisionTypes() |
| 6814 | + { |
| 6815 | + return new List<string> { "float", "datetime2", "datetimeoffset" }; |
| 6816 | + } |
| 6817 | + |
| 6818 | + public List<string> PrecisionAndScaleTypes() |
| 6819 | + { |
| 6820 | + return new List<string> { "decimal", "numeric" }; |
| 6821 | + } |
6761 | 6822 | } |
6762 | 6823 |
|
6763 | 6824 | public class SqlServerToJavascript : IDatabaseToPropertyType |
|
6802 | 6863 | { |
6803 | 6864 | return new List<string> { "geography", "geometry" }; |
6804 | 6865 | } |
| 6866 | + |
| 6867 | + public List<string> PrecisionTypes() |
| 6868 | + { |
| 6869 | + return new List<string> { "float", "datetime2", "datetimeoffset" }; |
| 6870 | + } |
| 6871 | + |
| 6872 | + public List<string> PrecisionAndScaleTypes() |
| 6873 | + { |
| 6874 | + return new List<string> { "decimal", "numeric" }; |
| 6875 | + } |
6805 | 6876 | } |
6806 | 6877 |
|
6807 | 6878 | public class DigitalSignaturePublic |
@@ -11731,13 +11802,19 @@ and limitations under the License. |
11731 | 11802 | protected Dictionary<string, string> StoredProcedureParameterDbType; // [SQL Data Type] = SqlDbType. (For consistent naming) |
11732 | 11803 | protected Dictionary<string, string> DbTypeToPropertyType; // [SQL Data Type] = Language type. |
11733 | 11804 | protected List<string> SpatialTypes; |
| 11805 | + protected List<string> PrecisionAndScaleTypes; |
| 11806 | + protected List<string> PrecisionTypes; |
11734 | 11807 |
|
11735 | 11808 | protected string DatabaseEdition, DatabaseEngineEdition, DatabaseProductVersion, DatabaseName; |
11736 | 11809 | protected int DatabaseProductMajorVersion; |
11737 | 11810 |
|
11738 | 11811 | public bool IncludeSchema { get; protected set; } |
11739 | 11812 | public bool DoNotSpecifySizeForMaxLength { get; protected set; } |
11740 | 11813 |
|
| 11814 | + public bool IsSpatialType(string propertyType) => propertyType != null && SpatialTypes != null && SpatialTypes.Contains(propertyType); |
| 11815 | + public bool IsPrecisionAndScaleType(string propertyType) => propertyType != null && PrecisionAndScaleTypes != null && PrecisionAndScaleTypes.Contains(propertyType); |
| 11816 | + public bool IsPrecisionType(string propertyType) => propertyType != null && PrecisionTypes != null && PrecisionTypes.Contains(propertyType); |
| 11817 | + |
11741 | 11818 | protected abstract string TableSQL(); |
11742 | 11819 | protected abstract string ForeignKeySQL(); |
11743 | 11820 | protected abstract string ExtendedPropertySQL(); |
@@ -11774,6 +11851,8 @@ and limitations under the License. |
11774 | 11851 |
|
11775 | 11852 | DbTypeToPropertyType = databaseToPropertyType.GetMapping(); |
11776 | 11853 | SpatialTypes = databaseToPropertyType.SpatialTypes(); |
| 11854 | + PrecisionTypes = databaseToPropertyType.PrecisionTypes(); |
| 11855 | + PrecisionAndScaleTypes = databaseToPropertyType.PrecisionAndScaleTypes(); |
11777 | 11856 | DatabaseEdition = null; |
11778 | 11857 | DatabaseEngineEdition = null; |
11779 | 11858 | DatabaseProductVersion = null; |
@@ -12201,7 +12280,7 @@ and limitations under the License. |
12201 | 12280 | Precision = ChangeType<byte>(rdr["NUMERIC_PRECISION"]), |
12202 | 12281 | Scale = ChangeType<int>(rdr["NUMERIC_SCALE"]), |
12203 | 12282 | UserDefinedTypeName = rdr["USER_DEFINED_TYPE"].ToString().Trim(), |
12204 | | - IsSpatial = SpatialTypes.Contains(dataType) |
| 12283 | + IsSpatial = IsSpatialType(dataType) |
12205 | 12284 | }; |
12206 | 12285 |
|
12207 | 12286 | if (string.IsNullOrEmpty(parameter.Name)) |
|
0 commit comments